Java 1ms solution


  • 0
    M
    public int guessNumber(int n) {
        int my = n / 2, tmp = n / 2, result = 0;
        while ((result = guess(my)) != 0) {
            tmp = tmp / 2 == 0 ? 1 : tmp / 2;
            my = my + result * tmp;
        }
        return my;
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.