1ms JAVA solution


  • 0
    F
    public int guessNumber(int n) {
            int low = 1, high = n;
            while (low < high) {
                int mid = low + (high - low) / 2;
                switch (guess(mid)) {
                    case 0:
                        return mid;
                    case 1:
                        low = mid + 1;
                        break;
                    default:
                        high = mid - 1;
                }
            }
            return low;
        }
    

Log in to reply
 

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