Cpp Solution using sorting


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

Log in to reply
 

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