My simple 1ms Java Code

  • 0
    public class Solution extends GuessGame {
        public int guessNumber(int n) {
            if(n==1) return 1;
            int lower = 1;
            int higher = n;
            int result;
                result = lower+(higher-lower)/2;
                if(guess(result)==0) break;
                else if(guess(result)==1){
                    if(result==n-1) return n;
                    lower = result;
                else higher = result;
            return result;

Log in to reply

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