```
class Solution {
public:
int mySqrt(int x) {
if (x == 1) return x;
int l = 0, r = min((x >> 1) + 1, 46341);
while (r - l > 1) {
int mid = (l + r) >> 1;
if (mid * mid > x) r = mid;
else l = mid;
}
return l;
}
};
```