class Solution(object):
def singleNumbers(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
nums.sort()
res = []
# 特判:处理第一个和最后一个元素
if nums[0] != nums[1]:
res.append(nums[0])
if nums[-1] != nums[-2]:
res.append(nums[-1])
for i in range(1, len(nums) - 1):
if nums[i] == nums[i - 1] or nums[i] == nums[i + 1]:
continue
else:
res.append(nums[i])
return res
if __name__ == '__main__':
s = Solution()
print(s.singleNumbers(nums=[4, 1, 4, 6]))