您的位置:首页 > 其它

【leetcode】 260. Single Number III

2016-05-17 18:45 302 查看
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.

For example:

Given nums = [1, 2, 1, 3, 2, 5], return [3, 5].

感觉大家都用异或来做啊,用字典感觉好慢

class Solution(object):
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
dic = {}
for num in nums:
if num not in dic:
dic[num]=1
else:
del dic[num]
return dic.keys()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: