@@ -0,0 +1,1606 @@
+/***%0A * A peak element is an element that is greater than its neighbors.%0A *%0A * Given an input array where num%5Bi%5D != num%5Bi+1%5D, find a peak element and return its index.%0A *%0A * The array may contain multiple peaks, in that case return the index to any one of the peaks is fine.%0A *%0A * You may imagine that num%5B-1%5D = num%5Bn%5D = -Inf.%0A *%0A * For example, in array %5B1, 2, 3, 1%5D, 3 is a peak element and your function should return the index number 2.%0A *%0A * Note:%0A * Your solution should be in logarithmic complexity.%0A */%0A%0Apublic class Solution %7B%0A    // Brute force solution: linear scan, worst case complexity O(n)%0A    %0A    // Solution 1: Divide and Conquer O(log n)%0A    // If  V(mid - 1) %3C V(mid) && V(mid) %3E V(mid + 1) return;%0A    // If V(mid) %3C V(mid - 1), search in left half,%0A    // else if V(mid) %3C V(mid + 1), search in right half.%0A    public int findPeakElement(int%5B%5D num) %7B%0A        int n = num.length;%0A        if (n == 1) return 0;%0A        int i = 0, j = n - 1, mid;%0A        while(i %3C j) %7B%0A            mid = (i + j) / 2;%0A            if ((mid == 0 %7C%7C num%5Bmid%5D %3E num%5Bmid - 1%5D) && (mid == n - 1 %7C%7C num%5Bmid%5D %3E num%5Bmid + 1%5D))%0A                return mid;%0A            if (mid %3E 0 && num%5Bmid - 1%5D %3E num%5Bmid%5D)%0A                j = mid - 1;%0A            else if (mid %3C n - 1 && num%5Bmid%5D %3C num%5Bmid + 1%5D)%0A                i = mid + 1;%0A            else %7B%0A                int k = mid;%0A                while(k %3E= 0 && num%5Bk%5D == num%5Bmid%5D) k--;%0A                if (k == -1 %7C%7C num%5Bk%5D %3E num%5Bmid%5D)%0A                    j = k;%0A                else %0A                    i = mid + 1;%0A            %7D%0A        %7D%0A        return i;%0A    %7D%0A%7D%0A

add FindPeakElement.java