Skip to content

Commit 2e9dcbe

Browse files
committed
Runtime: 23 ms (Top 74.27%) | Memory: 18.7 MB (Top 49.37%)
1 parent b45c732 commit 2e9dcbe

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed
+18-17
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
// Runtime: 23 ms (Top 74.27%) | Memory: 18.7 MB (Top 49.37%)
12
class Solution {
23
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+
};

0 commit comments

Comments
 (0)