Quite easy to understand for beginners with python


  • 0
    S
    class Solution(object):
        def singleNonDuplicate(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            if nums[0] != nums[1]:
                return nums[0]
            elif nums[-1] != nums[-2]:
                return nums[-1]
            for i in range(1, (len(nums)-1)):
                if (nums[i] != nums[i+1]) and (nums[i] != nums[i-1]):
                    return nums[i]
    

Log in to reply
 

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