0069. x 的平方根 #175
Replies: 1 comment
-
c++ class Solution {
public:
int mySqrt(int x) {
if (x < 2) return x;
int left = 1, right = x;
while (left <= right) {
int mid = left + ((right - left) >> 1);
if (mid <= x / mid) {
left = mid + 1;
} else {
right = mid - 1;
}
}
return right;
}
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
0069. x 的平方根
https://algo.itcharge.cn/Solutions/0001-0099/sqrtx/
Beta Was this translation helpful? Give feedback.
All reactions