8000 src/bin/h-index.rs · bestgopher/leetcode@3601766 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3601766

Browse files
committed
src/bin/h-index.rs
1 parent 0731e61 commit 3601766

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/bin/h-index.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
fn main() {
2+
println!("{}", Solution::h_index(vec![3, 0, 6, 1, 5]));
3+
println!("{}", Solution::h_index(vec![1]));
4+
}
5+
6+
struct Solution;
7+
8+
impl Solution {
9+
pub fn h_index(citations: Vec<i32>) -> i32 {
10+
let mut citations = citations;
11+
citations.sort();
12+
13+
let mut h = 0;
14+
15+
for i in (0..citations.len()).rev() {
16+
if citations[i] > h {
17+
h += 1;
18+
}
19+
}
20+
21+
return h;
22+
}
23+
}

0 commit comments

Comments
 (0)
0