package leetcode;

/**
 * https://leetcode.com/problems/guess-number-higher-or-lower/
 */
public class Problem374 {
    // test case
    private static int guess(int num) {
        if (num == 1702766719) {
            return 0;
        } else if (num < 1702766719) {
            return 1;
        }
        return -1;
    }

    public int guessNumber(int n) {
        long lo = 1;
        long hi = n;
        while (lo <= hi) {
            long lmid = (lo + hi) / 2;
            int mid = (int) lmid;
            if (guess(mid) == 0) {
                return mid;
            } else if (guess(mid) < 0) {
                hi = mid - 1;
            } else {
                lo = mid + 1;
            }
        }
        throw new RuntimeException("Number not found");
    }

    public static void main(String[] args) {
        Problem374 prob = new Problem374();
        System.out.println(prob.guessNumber(2126753390));
    }
}

@@ -770,161 +770,7 @@
    %7D
-%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem374 prob = new Problem374();%0A        System.out.println(prob.guessNumber(2126753390));%0A    %7D
 %0A%7D%0A

Update problem 374