If value of start and end are max. range of integer.
So, by adding these 2 it will give Exception: java: integer number too large.
Hence, using 2nd approach this problem will not come.
// avoid using below thing
int mid = (start + end) / 2;
// correct approach
int mid = start + ((end - start) / 2);
No comments:
Post a Comment