Wednesday, 5 October 2016

H-Index (LeetCode)

Problem: H-Index
class Solution {
public:
    int hIndex(vector<int>& citations) {
        sort(citations.begin(), citations.end(), greater<int>());
        for(int i=0;i<citations.size();i++)
            if(citations[i]<=i)
                return i;
        return citations.size();
    }
};

No comments:

Post a Comment