LeetCode69题
程序员文章站
2022-03-19 11:57:08
...
public static int mySqrta(int x) {
int left = 0;
int right = x;
int ans = -1;
int mid = left + (right - left) / 2;
while (left <= right) {
if ((long) mid * mid <= x) {
ans = mid;
left = mid + 1;
} else {
right = mid - 1;
}
}
return ans;
}
上一篇: Django基础-day69
下一篇: leetcode【69】Sqrt(x)