Problem Summary
Given a sorted array of N integers, find the starting and ending position of a given target value.
Solution
We need to use binary search twice. The first is in range [0,…,N-1], and if we find a legal l, we ran the second binary search in range [l,..,N-1].
Be careful about how to calculate mid to prevent endless loop.
Code
|
|