首页 » 编程之美 » 正文

[leetcode_275]H-Index II

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

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;
    }
};

发表评论