Simple C++ Beats 100% Solutions


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

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.