ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

LeetCode69. x 的平方根(C++)

2026/8/20 3:29:12 拓冰建站 浏览量
LeetCode69. x 的平方根(C++)

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;}
};