LeetCode69. x 的平方根
- 题目链接
- 代码
题目链接
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;}
};