Skip to content

Commit fde7b1d

Browse files
authored
Create Solution.java
1 parent a652501 commit fde7b1d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

solution/0274.H-Index/Solution.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public int hIndex(int[] citations) {
3+
int n = citations.length;
4+
int[] cnt = new int[n + 1];
5+
for (int c : citations) {
6+
if (c <= n) {
7+
++cnt[c];
8+
} else {
9+
++cnt[n];
10+
}
11+
}
12+
int sum = 0;
13+
for (int i = n; i >= 0; --i) {
14+
sum += cnt[i];
15+
if (sum >= i) {
16+
return i;
17+
}
18+
}
19+
return 0;
20+
}
21+
}

0 commit comments

Comments
 (0)