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
时间: 2024-09-29 10:03:52