My Python Two-Line Solution


  • 0
    S

    Hey guys, just for your information.

    class Solution(object):
        def singleNumber(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            nums.sort()
            return list(set(nums) - set(nums[1::2]))[0]
    

  • 1

    @Supreme_Lei
    You should have O(n) time complexity and try not to use extra memory. Your complexity is O(n*log n) and you have 2 sets, which use extra memory.


Log in to reply
 

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