首页 > 代码库 > leetcode:Single Number【Python版】

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] = 211         for i in B:12             if B[i] == 1:13                 ret = i14                 break15         return ret

 

leetcode:Single Number【Python版】