Middle of binary search

When doing binary search, we need to calculate the middle pointer.
Be careful about the overflow. Because it is leftStart + rightEnd might overflow.

int mid = leftStart + (rightEnd - leftStart) / 2;

The following is not the same.

int mid = (leftStart + rightEnd) / 2;

你可能感兴趣的:(Middle of binary search)