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