Java simple straightforward


  • 0
    J
    public int hIndex(int[] citations) {
    	Arrays.sort(citations);
    	int h = citations.length;
    
    	while (h > 0) {
    		int i = citations.length - 1;
    		int count = 0;
    		while (i >= 0) {
    			if (citations[i] >= h) {
    				count++;
    			} else
    				break;
    			i--;
    		}
    		if (count >= h) {
    			return h;
    		}
    		h--;
    	}
    	return h;
    }

Log in to reply
 

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