My JAVA Solution easy to undertsand


  • 0
    L
    public class Solution {
        public int hIndex(int[] citations) {
            if(citations.length <= 0) return 0;
            Arrays.sort(citations);
            int maxH = 0, len = citations.length;
            
            if(citations[len-1] <= 0) maxH = 0;
            if(citations[0] >= len) {
                return len;
            }
            
            for(int i = 1; i < len; i++) {
                if(citations[len-1-i] <= i && citations[len-i] >= i) maxH = i;
            }
            
            return maxH;
        }
    }
    

Log in to reply
 

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