# LeetCode162. Find Peak Element

A peak element is an element that is greater than its neighbors.

Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.

The array may contain multiple peaks, in that case return the index to any one of the peaks is fine.

You may imagine that num[-1] = num[n] = -∞.

For example, in array [1, 2, 3, 1], 3 is a peak element and your function should return the index number 2.

Note:

Your solution should be in logarithmic complexity.

    static  int findPeakElementImp(int[] array, int s , int e){
if(e-s <= 1){
return array[e]> array[s]?e:s;
}
int mid = s+ (e-s)/2;
if(array[mid] > array[mid -1] && array[mid]> array[mid+1]){
return  mid;
}
if( array[mid] > array[mid+1]){
return findPeakElementImp(array ,s, mid);
}else{
return  findPeakElementImp(array, mid ,e);
}
}
static  public  void main(String[] args ){
int[] testArray ={1,2,6};
int result = findPeakElementImp(testArray, 0, testArray.length -1 );
System.out.println(result);
}

#### leetcode162. Find Peak Element

2017-03-11 12:36:07

#### Leetcode162. Find Peak Element

2016-12-08 10:48:56

#### Leetcode: Find Peak Element

2014-12-17 23:55:37

#### Find Peak Element --leetcode

2014-12-15 14:25:39

#### 【leetcode 分治法】Find Peak Element

2014-12-07 21:56:48

#### LintCode Find Peak Element II（查找峰值II）

2016-06-21 03:27:29

#### LeetCode(162) Find Peak Element

2015-01-01 16:36:25

#### LeetCode162——Find Peak Element

2015-08-03 14:36:24

#### leetcode_c++：Find Peak Element（162）

2016-06-14 23:44:23

#### 【LEETCODE】162-Find Peak Element [Python]

2016-01-08 19:45:05