标签:
public class Solution { public int findPeakElement(int[] nums) { if (nums == null || nums.length == 0 || nums.length == 1) { return 0; } int l = 0; int r = nums.length - 1; while (l <= r) { if (l == r) return l; int mid = (l+r)/2; if (nums[mid] < nums[mid + 1]) { l = mid +1; } else { r = mid; } } return l; } }
用二分法 可是自己写边界写错了!!!
标签:
原文地址:http://www.cnblogs.com/77rousongpai/p/4513974.html