题目:一个数组里,除了三个数是唯一出现的,其余的数都出现偶数次,找出这三个数中的任意一个。
分析:采用哈希法。
code:
def find1Num(arr):
if arr is None or len(arr) <= 0:
return
hashTable = dict()
i = 0
while i < len(arr):
if arr[i] not in hashTable:
hashTable[arr[i]] = 1
else:
hashTable[arr[i]] = 2
i += 1
return hashTable
if __name__ == "__main__":
arr = [6, 3, 4, 5, 9, 4, 3]
hashTable = find1Num(arr)
for k, v in hashTable.items():
if v == 1:
print(k)