162. Find Peak Element
There may exsists many peak elements in array, only need to return 1 index. If it’s a sorted array, answer will be first or last element.
random select 1 element, if not peak element, if left neighbors larger than it, peak will exists in left part, otherwise right part. Notice the edge case where length == 2, then simply comes to start/end.
34. Search for a Range
Simple binary search to find initial value, then search for the range. My solution is a little complex to loop to boundary, worst case go to O(n)
. actually, start = find(target), end = find(target + 1) -1
.