3 ms·
This can still cause signed overflow if left is close enough to INT_MAX and right is close enough to INT_MIN. The actual overflow-less way to compute the avera
by 10000truths 5y ago
This can still cause signed overflow if left is close enough to INT_MAX and right is close enough to INT_MIN.
The actual overflow-less way to compute the average of two numbers is:
(a/2) + (b/2) + (((a%2) + (b%2))/2)
- anonymoushn 5y agoright is generally not less than left in the context of a binary search.