File tree 3 files changed +67
-0
lines changed
solution/2500-2599/2558.Take Gifts From the Richest Pile
3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -144,6 +144,30 @@ func (hp) Pop() (_ interface{}) { return }
144
144
func (hp) Push(interface{}) {}
145
145
```
146
146
147
+ ### ** Rust**
148
+
149
+ ``` rust
150
+ impl Solution {
151
+ pub fn pick_gifts (gifts : Vec <i32 >, k : i32 ) -> i64 {
152
+ let mut h = std :: collections :: BinaryHeap :: from (gifts );
153
+ let mut ans = 0 ;
154
+
155
+ for _ in 0 .. k {
156
+ if let Some (mut max_gift ) = h . pop () {
157
+ max_gift = (max_gift as f64 ). sqrt (). floor () as i32 ;
158
+ h . push (max_gift );
159
+ }
160
+ }
161
+
162
+ for x in h {
163
+ ans += x as i64 ;
164
+ }
165
+
166
+ ans
167
+ }
168
+ }
169
+ ```
170
+
147
171
### ** ...**
148
172
149
173
```
Original file line number Diff line number Diff line change @@ -126,6 +126,30 @@ func (hp) Pop() (_ interface{}) { return }
126
126
func (hp) Push(interface{}) {}
127
127
```
128
128
129
+ ### ** Rust**
130
+
131
+ ``` rust
132
+ impl Solution {
133
+ pub fn pick_gifts (gifts : Vec <i32 >, k : i32 ) -> i64 {
134
+ let mut h = std :: collections :: BinaryHeap :: from (gifts );
135
+ let mut ans = 0 ;
136
+
137
+ for _ in 0 .. k {
138
+ if let Some (mut max_gift ) = h . pop () {
139
+ max_gift = (max_gift as f64 ). sqrt (). floor () as i32 ;
140
+ h . push (max_gift );
141
+ }
142
+ }
143
+
144
+ for x in h {
145
+ ans += x as i64 ;
146
+ }
147
+
148
+ ans
149
+ }
150
+ }
151
+ ```
152
+
129
153
### ** ...**
130
154
131
155
```
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn pick_gifts ( gifts : Vec < i32 > , k : i32 ) -> i64 {
3
+ let mut h = std:: collections:: BinaryHeap :: from ( gifts) ;
4
+ let mut ans = 0 ;
5
+
6
+ for _ in 0 ..k {
7
+ if let Some ( mut max_gift) = h. pop ( ) {
8
+ max_gift = ( max_gift as f64 ) . sqrt ( ) . floor ( ) as i32 ;
9
+ h. push ( max_gift) ;
10
+ }
11
+ }
12
+
13
+ for x in h {
14
+ ans += x as i64 ;
15
+ }
16
+
17
+ ans
18
+ }
19
+ }
You can’t perform that action at this time.
0 commit comments