@@ -0,0 +1,1416 @@
+/**%09A peak element is an element that is greater than its neighbors.%0A *%0A * %09Given an input array where num%5Bi%5D %E2%89%A0 num%5Bi+1%5D, find a peak element and return its index.%0A *%0A *%09The array may contain multiple peaks, in that case return the index to any one of the peaks is fine.%0A *%0A *%09You may imagine that num%5B-1%5D = num%5Bn%5D = -%E2%88%9E.%0A *%0A *%09For example, in array %5B1, 2, 3, 1%5D, 3 is a peak element and your function should return the index number 2.%0A *%0A *%09Author: matao%0A */%0A%0Apublic class FindPeakElement %7B%0A%09public static int findPeak(int%5B%5D nums) %7B%0A%09%09int start = 0, end = nums.length-1;%0A%09%09//A%E5%8C%85%E5%90%AB%E4%B8%89%E4%B8%AA%E6%88%96%E4%BB%A5%E4%B8%8A%E7%9A%84%E6%95%B0%0A        while(start + 1 %3C end) %7B%0A            int mid = start + (end - start) / 2;%0A            if(nums%5Bmid%5D %3E nums%5Bmid-1%5D && nums%5Bmid%5D %3E nums%5Bmid+1%5D)%0A                return mid;%0A            else if (nums%5Bmid%5D %3E nums%5Bmid+1%5D)%0A                end = mid;%0A            else%0A                start = mid;%0A        %7D%0A        //A%E5%8C%85%E5%90%AB%E4%B8%A4%E4%B8%AA%E6%95%B0%0A        if((start + 1 == end) && nums%5Bstart%5D %3C nums%5Bend%5D)%0A            return end;%0A        //A%E5%8F%AA%E6%9C%89%E4%B8%80%E4%B8%AA%E6%95%B0%0A        return start;%0A%09%7D%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09int%5B%5D nums1 = %7B1%7D;%0A%09%09int%5B%5D nums2 = %7B1, 2%7D;%0A%09%09int%5B%5D nums3 = %7B2, 1%7D;%0A%09%09int%5B%5D nums4 = %7B1, 2, 1, 3, 4, 5, 7, 6%7D;%0A%09%09int%5B%5D nums5 = %7B1, 2, 2, 3%7D;%0A%09%09System.out.println(findPeak(nums1));%0A%09%09System.out.println(findPeak(nums2));%0A%09%09System.out.println(findPeak(nums3));%0A%09%09System.out.println(findPeak(nums4));%0A%09%09System.out.println(findPeak(nums5));%0A%09%7D%0A%7D

add find peak solution