https://leetcode.com/problems/find-peak-element/?envType=study-plan-v2&envId=top-interview-150
class Solution {
public int findPeakElement(int[] nums) {
int ans = 0;
int max = Integer.MIN_VALUE;
for (int i = 0; i < nums.length; i++) {
if (nums[i] > max) {
max = nums[i];
ans = i;
}
}
return ans;
}
}
class Solution {
public int findPeakElement(int[] nums) {
int left = 0;
int right = nums.length - 1;
while (left < right) {
int mid = (left + right) / 2;
if (nums[mid] < nums[mid + 1]) {
left = mid + 1;
} else {
right = mid;
}
}
return left;
}
}