c++ sort method


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

Log in to reply
 

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