Complete the code to start the binary search with the correct initial left index.
int left = [1];The search starts from the first index, which is 0.
Complete the code to calculate the middle index correctly.
int mid = left + ([1] - left) / 2;
We calculate mid between left and right to avoid overflow.
Fix the error in the condition to check if the left half is sorted.
if (nums[left] [1] nums[mid])
The left half is sorted if nums[left] is less than nums[mid].
Fill both blanks to update the search range when the target is in the left sorted half.
if (target [1] nums[mid] && target [2] nums[left]) { right = mid - 1; } else { left = mid + 1; }
Target must be less than nums[mid] and greater or equal to nums[left] to be in left half.
Fill all three blanks to update the search range when the right half is sorted.
if (target [1] nums[right] && target [2] nums[mid]) { left = mid + 1; } else { right = mid [3] 1; }
Target is between mid and right, so left moves up and right moves down by 1.
