class Solution { public int mySqrt(int x) { if(x < 2) return x; int l = 0, r = x; while(l < r) { int mid = (l + r) >> 1; if(x / mid < mid) { r = mid; } else if(x / mid > mid) { l = mid + 1; } else { return mid; } } return l - 1; } public int mySqrt(int x) { if(x < 2) return x; int l = 0, r = x; while(l <= r) { int mid = (l + r) >> 1; if(x / mid < mid) { r = mid - 1; } else { l = mid + 1; } } return l - 1; } }