File tree 1 file changed +18
-17
lines changed
scripts/algorithms/H/H-Index II
1 file changed +18
-17
lines changed Original file line number Diff line number Diff line change
1
+ // Runtime: 23 ms (Top 74.27%) | Memory: 18.7 MB (Top 49.37%)
1
2
class Solution {
2
3
public:
3
- int hIndex (vector<int >& citations) {
4
- int start = 0 , end = citations.size ()-1 ;
5
- int n = citations.size ();
6
- while (start <= end){
7
- int mid = start + (end - start) / 2 ;
8
- int val = citations[mid];
9
- if (val == (n - mid)) return citations[mid];
10
- else if (val < n - mid){
11
- start = mid + 1 ;
12
- }
13
- else {
14
- end = mid - 1 ;
15
- }
16
- }
17
- return n - start;
18
- }
19
- };
4
+ int hIndex (vector<int >& citations) {
5
+ int start = 0 , end = citations.size ()-1 ;
6
+ int n = citations.size ();
7
+ while (start <= end){
8
+ int mid = start + (end - start) / 2 ;
9
+ int val = citations[mid];
10
+ if (val == (n - mid)) return citations[mid];
11
+ else if (val < n - mid){
12
+ start = mid + 1 ;
13
+ }
14
+ else {
15
+ end = mid - 1 ;
16
+ }
17
+ }
18
+ return n - start;
19
+ }
20
+ };
You can’t perform that action at this time.
0 commit comments