题目描述 题目链接 代码 public int mySqrt(int x) { int left = 0; int right = x; int res = -1; while (left <= right) { int mid = (left + right) >> 1; //强转 if ((long) mid * mid <= x) { res = mid; left = mid + 1; } else { right = mid - 1; } } return res; } 运行结果