--- title: "sqrt(x)" created: 2025-11-28 tags: - 算法 --- # sqrt(x) ## 题目 [sqrt(x)](https://leetcode.com/problems/sqrtx/description/) ![[image-e9179258.png]] ## 思路分析 向下取整的开方 那就是小于等于答案的第一个整数 用x√模版 ## 代码实现 ```java class Solution { public: int mySqrt(int x) { long long l=1,r=x; while(l>1; if(mid*mid<=x) l=mid; else r=mid-1; } return r; } }; ``` ## 同类题型 ## 视频讲解 --- ⬅️ [[2-Learning/02-算法/03-刷题理模型/二分相关模型/5、递增三元组|5、递增三元组]] 🏠 [[00-刷题理模型]] ➡️ [[二分相关模型|二分相关模型]]