【LeetCode-Python】136. Single Number

Given an array of integers, every element appears twice except for one. Find that single one.

Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

简单解释:list肯定是含有奇数个元素,找出其中只出现一次的那个数(唯一)

Solution1[Python]: LeetCode通过

class Solution(object):
    def singleNumber(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        nums.sort()
        for i in range(len(nums)/2):
            if nums[-1] != nums[-2]:
                return nums[-1]
            nums.pop()
            nums.pop()
        return nums[0]

你可能感兴趣的:(【LeetCode-Python】136. Single Number)