4ms C++ solution using sort


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

Log in to reply
 

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