The question below is listed for both templates II and III.
https://leetcode.com/problems/find-peak-element/
However, the accepted code below doesn't match template II exactly.
public int findPeakElement(int[] nums) {
int l = 0, r = nums.length - 1;
while (l < r) {
int mid = l + (r - l) / 2;
if (nums[mid] > nums[mid + 1])
r = mid;
else
l = mid + 1;
}
return l;
}
Are you able to use either template II or III?
https://leetcode.com/explore/learn/card/binary-search/136/template-analysis/935/