forked from KnowledgeCenterYoutube/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path274_H-Index
42 lines (36 loc) · 892 Bytes
/
274_H-Index
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Leetcode 274: H-Index
Detailed video explanation: https://youtu.be/zzTUtpBQh4k
========================================================
C++:
----
class Solution {
public:
int hIndex(vector<int>& citations) {
sort(citations.begin(), citations.end());
int n = citations.size(), i;
for(i = 1; i <= n; ++i)
if(citations[n-i] < i) break;
return i-1;
}
};
Java:
-----
class Solution {
public int hIndex(int[] citations) {
Arrays.sort(citations);
int n = citations.length, i;
for(i = 1; i <= n; ++i)
if(citations[n-i] < i) break;
return i-1;
}
}
Python3:
-------
class Solution:
def hIndex(self, citations: List[int]) -> int:
citations.sort()
n, i = len(citations), 1
while i <= n:
if citations[n-i] < i: break
i += 1
return i-1