File tree 3 files changed +67
-0
lines changed
solution/0200-0299/0274.H-Index
3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -227,6 +227,30 @@ public:
227
227
};
228
228
```
229
229
230
+ ### **Rust**
231
+
232
+ ```rust
233
+ impl Solution {
234
+ #[allow(dead_code)]
235
+ pub fn h_index(citations: Vec<i32>) -> i32 {
236
+ let mut citations = citations;
237
+ citations.sort_by(|&lhs, &rhs| {
238
+ rhs.cmp(&lhs)
239
+ });
240
+
241
+ let n = citations.len();
242
+
243
+ for i in (1..=n).rev() {
244
+ if citations[i - 1] >= i as i32 {
245
+ return i as i32;
246
+ }
247
+ }
248
+
249
+ 0
250
+ }
251
+ }
252
+ ```
253
+
230
254
### ** Go**
231
255
232
256
``` go
Original file line number Diff line number Diff line change @@ -218,6 +218,30 @@ public:
218
218
};
219
219
```
220
220
221
+ ### **Rust**
222
+
223
+ ```rust
224
+ impl Solution {
225
+ #[allow(dead_code)]
226
+ pub fn h_index(citations: Vec<i32>) -> i32 {
227
+ let mut citations = citations;
228
+ citations.sort_by(|&lhs, &rhs| {
229
+ rhs.cmp(&lhs)
230
+ });
231
+
232
+ let n = citations.len();
233
+
234
+ for i in (1..=n).rev() {
235
+ if citations[i - 1] >= i as i32 {
236
+ return i as i32;
237
+ }
238
+ }
239
+
240
+ 0
241
+ }
242
+ }
243
+ ```
244
+
221
245
### ** Go**
222
246
223
247
``` go
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ #[ allow( dead_code) ]
3
+ pub fn h_index ( citations : Vec < i32 > ) -> i32 {
4
+ let mut citations = citations;
5
+ citations. sort_by ( |& lhs, & rhs| {
6
+ rhs. cmp ( & lhs)
7
+ } ) ;
8
+
9
+ let n = citations. len ( ) ;
10
+
11
+ for i in ( 1 ..=n) . rev ( ) {
12
+ if citations[ i - 1 ] >= i as i32 {
13
+ return i as i32 ;
14
+ }
15
+ }
16
+
17
+ 0
18
+ }
19
+ }
You can’t perform that action at this time.
0 commit comments