import java.util.*; public class Solution { public int findPeakElement (int[] nums) { // 定义快慢指针,起始差为1,之后同步走来比较 int ret =0; if(nums.length==2&&nums[1]>nums[0]){ ret = 1; } int f = 2; int s = 0; //注意边界处以而满足 if(nums.length>2&&nums[nums.length-1]>nums[nums.length-2]){ ret = nums.length-1; } while(f<nums.length){ if(nums[f-1]>nums[s]&&nums[f-1]>nums[f]){ ret = f-1; break; }else{ f++; s++; } } return ret; } }