leetcode:Single Number【Python版】

1、用双重循环逐个遍历(超时)

2、用list B的append和remove函数(超时)

3、用dict B(AC)

 1 class Solution:
 2     # @param A, a list of integer
 3     # @return an integer
 4     def singleNumber(self, A):
 5         B = {}
 6         for i in A:
 7             if i not in B:
 8                 B[i] = 1
 9             else:
10                 B[i] = 2
11         for i in B:
12             if B[i] == 1:
13                 ret = i
14                 break
15         return ret

 

posted @ 2014-10-18 23:44  ZH奶酪  阅读(831)  评论(0编辑  收藏  举报