Simple java solution using sort


  • 0
    J
    public class Solution {
        public int hIndex(int[] citations) {
            
            int index=0,size=citations.length;
            Arrays.sort(citations);
            int max=0;
            
            while(index<size)
            {
                int cit = citations[index];
                int noOfBooks=size-index;
                
                if(cit>=noOfBooks) max=Math.max(max,noOfBooks);
                index++;
            }
            
            return max;
            
        }
    }
    

Log in to reply
 

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