leetcode Single Number python
Single Number
Given an array of integers, every element appears twice except for one. Find that single one.
python code:
class Solution:
# @param {integer[]} nums
# @return {integer}
def singleNumber(self, nums):
B={}
for i in nums:
if i not in B: #建立一个dict,遍历此list,将其值作为key,并简单的将其出现次数离散化为1和2作为value
B[i]=1
else:
B[i]=2
for i in B:
if B[i] == 1:
ret=i #遍历dict,如果某个key对应的value为1,则返回该值
break
return ret