Binary Search
1 | class Solution { |
Remarks:
- TC: $O(\log n)$
- In a standard binary search senario,
left
is always the first index that is>=target
;right
is at the last index that is<target
. Why? because thewhile
condition isleft <= right
, and the loop ends whenleft > right
.