LeetCode每日一题(2020.5.9)
简单二分,注意爆int
class Solution {
public int mySqrt(int x) {
int l = 0, r = x;
while (l < r) {
int mid = (int)(((long)l + r + 1) >> 1);
if ((long)mid * mid <= x) l = mid;
else r = mid - 1;
}
return l;
}
}