"""
一个整型数组 nums 里除两个数字之外,其他数字都出现了两次。请写程序找出这两个只出现一次的数字。
要求时间复杂度是O(n),空间复杂度是O(1)。
请封装成一个函数,nums 为参数
示例 1:
输入:nums = [4,1,4,6]
输出:[1,6] 或 [6,1]
示例 2:
输入:nums = [1,2,10,4,1,4,3,3]
输出:[2,10] 或 [10,2]
限制:
2 <= nums.length <= 10000
"""
def test(nums):
length = len(nums)
result = []
if length < 2:
print('error nums...')
return result
nums.sort()
i = 0
while i < length-1:
if nums[i] == nums[i+1]:
i += 2
if i == length - 1:
result.append(nums[i])
else:
result.append(nums[i])
i += 1
return result
nums1 = [-5, 1, 6, -3, 6, -3, 1, 10]
list1 = test(nums1)
print(list1)