@@ -0,0 +1,1476 @@
+package main.algorithm.leetcode;%0A%0Aimport org.junit.Test;%0A%0A/**%0A * Title : main.algorithm.leetcode %3Cbr%3E%0A * Description :%0A *   Runtime: 0 ms, faster than 100.00%25 of Java online submissions for Guess Number Higher or Lower.%0A *   Memory Usage: 36.3 MB, less than 6.45%25 of Java online submissions for Guess Number Higher or Lower.%0A * @author chile%0A * @version 1.0%0A * @date 2020/4/16 11:23%0A */%0Apublic class GuessNumberHigherOrLower %7B%0A%0A%0A    /**%0A     * Forward declaration of guess API.%0A     * @param  num   your guess%0A     * @return %09     -1 if num is lower than the guess number%0A     *%09%09%09      1 if num is higher than the guess number%0A     *               otherwise return 0%0A     * int guess(int num);%0A     */%0A    private static class GuessGame %7B%0A        int guess(int num) %7B%0A            return Integer.compare(num, 2);%0A        %7D%0A    %7D%0A%0A    public class Solution extends GuessGame %7B%0A        public int guessNumber(int n) %7B%0A            if (n == 1) %7B%0A                return 1;%0A            %7D%0A            int p = n %3E%3E%3E 1, i = 1, j = n, t = 0;%0A            while (i %3C= j) %7B%0A                t = guess(p);%0A                if (t == 0) %7B%0A                    return p;%0A                %7D else if (t %3C 0) %7B%0A                    i = p + 1;%0A                %7D else %7B%0A                    j = p - 1;%0A                %7D%0A                p = (i + j) %3E%3E%3E 1;%0A            %7D%0A            return 0;%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void test1() %7B%0A        assert new Solution().guessNumber(2) == 2;%0A    %7D%0A%0A%7D%0A

guess number higher or lower