package leetcode;

/**
 * https://leetcode.com/problems/h-index/
 */
public class Problem274 {
    public int hIndex(int[] citations) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem274 prob = new Problem274();
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -167,127 +167,941 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem274 prob = new Problem274(
+Arrays.sort(citations);%0A        int n = citations.length;%0A        for (int h = n; h %3E= 0; h--) %7B%0A            int idx = binarySearch(citations, h, 0, n-1);%0A            System.out.println(%22h=%22 + h+ %22, n-h=%22 + (n-h) + %22, idx=%22 + idx);%0A            int x = n - idx;%0A            System.out.println(%22x=%22 + x);%0A            if (x %3E= h) %7B%0A                return h;%0A            %7D%0A        %7D%0A        return 0;%0A    %7D%0A%0A    private int binarySearch(int%5B%5D citations, int val, int lo, int hi) %7B%0A        if (lo %3E hi) %7B%0A            return lo;%0A        %7D%0A        int mid = (lo + hi) / 2;%0A        if (citations%5Bmid%5D == val) %7B%0A            int newMid = mid;%0A            while (newMid %3E= 0 && citations%5BnewMid%5D == val) %7B%0A                newMid--;%0A            %7D%0A            return ++newMid;%0A        %7D%0A        if (citations%5Bmid%5D %3E val) %7B%0A            return binarySearch(citations, val, lo, mid-1);%0A        %7D%0A        return binarySearch(citations, val, mid+1, hi
 );%0A 

Solve problem 274