老师,请问作业leetcode第278题
为什么int mid = left + (right-left) / 2;比int mid = (left + right) / 2;运行的更快?
public class Solution extends VersionControl {
public int firstBadVersion(int n) {
int left = 0, right = n;
while(left < right) {
// 这里为什么写成int mid = (left + right) / 2就会超时?
int mid = left + (right-left) / 2;
if(isBadVersion(mid)) right = mid;
else left = mid+1;
}
return left;
}
}