diff --git a/solutions/274. H-Index.md b/solutions/274. H-Index.md index d33053b..4f6f339 100644 --- a/solutions/274. H-Index.md +++ b/solutions/274. H-Index.md @@ -51,16 +51,15 @@ private: public: int hIndex(vector& 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 } }; ```