Before this problem, I have always use

```
mid = (start+end)) / 2;
```

To get the middle value, but this can caused OVERFLOW !

when start and end are all about INT_MAX , then (start+end) of course will be overflow !

To avoid the problem we can use

```
mid = start+(end-start)/2;
```

Here is the AC implementation

// Forward declaration of isBadVersion API.

bool isBadVersion(int version);

```
class Solution {
public:
int firstBadVersion(int n) {
int start=0, end=n;
cout<<end-start<<end;
while(end-start>1){
int mid=start+(end-start)/2;
/** mid = (start+end)) / 2; **/
if(isBadVersion(mid)) end=mid;
else start=mid;
}
return end;
}
};
```