@@ -0,0 +1,1514 @@
+/**%0A * Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?%0A *%0A * Hint:%0A *%0A * Expected runtime complexity is in O(log n) and the input is sorted.%0A *%0A * Tags: Binary Search%0A *%0A * Similar Problems: (M) H-Index%0A */%0Apublic class HIndex2 %7B%0A%0A    public int hIndex(int%5B%5D citations) %7B%0A        if (citations == null %7C%7C citations.length == 0) return 0;%0A        int l = 0;%0A        int h = citations.length;%0A        int mid;%0A        while (l %3C h) %7B%0A            mid = l + (h - l) / 2;%0A            if (citations%5Bmid%5D == citations.length - mid) %7B%0A                return citations.length - mid;%0A            %7D else if (citations%5Bmid%5D %3E citations.length - mid) %7B%0A                h = mid;%0A            %7D else %7B%0A                l = mid + 1;%0A            %7D%0A        %7D%0A        return citations.length - h;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        HIndex2 h2 = new HIndex2();%0A        int ans;%0A%0A        // %5B%5D -%3E 0%0A        int%5B%5D citations1 = new int%5B0%5D;%0A        ans = h2.hIndex(citations1);%0A        System.out.println(ans);%0A%0A        // %5B1%5D -%3E 1%0A        int%5B%5D citations2 = new int%5B%5D%7B1%7D;%0A        ans = h2.hIndex(citations2);%0A        System.out.println(ans);%0A%0A        // %5B1.2.3.4.5%5D -%3E 3%0A        int%5B%5D citations3 = new int%5B%5D%7B1,2,3,4,5%7D;%0A        ans = h2.hIndex(citations3);%0A        System.out.println(ans);%0A%0A        // %5B5,6,7,8,9%5D -%3E 5%0A        int%5B%5D citations4 = new int%5B%5D%7B5,6,7,8,9%7D;%0A        ans = h2.hIndex(citations4);%0A        System.out.println(ans);%0A    %7D%0A%7D%0A

add 275 H-Index 2