🟢 剑指 Offer II 072. 求平方根
LeetCode 提示
题目难度 简单
原题链接 🔗 leetcode
#
题解1经 典 送 命 题
class Solution { public int mySqrt(int x) { int lo=0, hi=x, mid, ans=0; while (lo<=hi) { mid = lo+(hi-lo)/2; if ((long)mid*mid <= x) { ans = mid; lo=mid+1; } else { hi=mid-1; } }
return ans; }}