public int mySqrt(int x) {
        int begin = 1, end = x;
        int ans = 0;
        while (begin <= end) {
            int mid = begin + (end - begin) / 2;
            if (mid <= x / mid) {
                begin = mid + 1;
                ans = mid;
            } else {
                end = mid - 1;
            }
        }
        return ans;
    }