赞
踩
https://leetcode.cn/problems/sqrtx/description/
class Solution {
public:
int mySqrt(int x) {
int right = x, left = 0, ans = -1;
while(left <= right){
long long mid = left + (right - left) / 2;
if(mid * mid <= x){
ans = mid;
left = mid +1;
}
else{
right = mid - 1;
}
}
return ans;
}
};
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。