Thursday, September 3, 2015

[LeetCode] H-Index

This question can be found https://leetcode.com/problems/h-index/


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