1 ms, Java clean and easy to understand


  • 0
    V
            if(nums.length == 0)
                return 0;
            int i = 0, j = nums.length - 1, m = 0;
            while(i < j)
            {
                m = i + (j - i) / 2;
                if(m % 2 == 1)
                {
                    if(nums[m - 1] == nums[m])
                        i = m + 1;
                    else
                        j = m - 1;
                }
                else
                {
                    if(nums[m + 1] == nums[m])
                        i = m;
                    else
                        j = m;
                }
            }
            return nums[i];

Log in to reply
 

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