My Python concise code beats 98%


  • 0
    5

    '''
    class Solution(object):
    def singleNonDuplicate(self, nums):
    """
    :type nums: List[int]
    :rtype: int
    """
    if len(nums) == 1:
    return nums[0]
    left, right = 0, len(nums) - 1
    while left < right:
    mid = (left + right) / 2
    if nums[mid] == nums[mid + 1]:
    mid -= 1
    if (mid - left + 1) % 2 == 1:
    right = mid
    else:
    left = mid + 1
    return nums[left]
    '''


Log in to reply
 

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