[leetcode_275]H-Index II

此题虽然能过,但是并未使用o(logn)的解法, mark一下,下次来解。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
class Solution {
public:
    int hIndex(vector<int>& citations) {
        //sort(citations.begin(), citations.end(), greater<int>());
        int size = citations.size();
        int max = 0;
        for (int i = size - 1; i >= 0; i--) {
            int j = size - 1 - i;
            if (citations[i] >= j + 1) {
                max = j + 1;
            }
        }
        return max;
    }
};
Licensed under CC BY-NC-SA 4.0