mirror of
https://github.com/ShusenTang/LeetCode.git
synced 2024-09-02 14:20:01 +00:00
Update 274. H-Index.md
This commit is contained in:
parent
7090ba5593
commit
b821c8f482
@ -51,16 +51,15 @@ private:
|
||||
public:
|
||||
int hIndex(vector<int>& citations) {
|
||||
int n = citations.size();
|
||||
if(!n) return 0;
|
||||
int left = 0, right = n - 1;
|
||||
while(left <= right){
|
||||
if(left == right) return min(citations[left], n - left);
|
||||
|
||||
while(left < right){
|
||||
int k = partition(citations, left, right);
|
||||
if(n - k == citations[k]) return citations[k];
|
||||
if(n - k > citations[k]) left = k + 1;
|
||||
else right = k;
|
||||
}
|
||||
return 0;
|
||||
return min(citations[left], n - left); // left == right
|
||||
}
|
||||
};
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user