题解 | #数组中只出现一次的两个数字#
数组中只出现一次的两个数字
https://www.nowcoder.com/practice/389fc1c3d3be4479a154f63f495abff8
# 在评论区看了很多哈希操作都关于dict, 这里提供一个set思路,仅供交流
#
class Solution:
def FindNumsAppearOnce(self , array: List[int]) -> List[int]:
# write code here
lst = []
sec_lst = []
for i in range(len(array)):
if array[i] in lst:
sec_lst.append(array[i])
else:
lst.append(array[i])
# 取出现一次的集合跟出现多次的集合的差集
return (list(set(lst)-set(sec_lst)))
#题解#
#
class Solution:
def FindNumsAppearOnce(self , array: List[int]) -> List[int]:
# write code here
lst = []
sec_lst = []
for i in range(len(array)):
if array[i] in lst:
sec_lst.append(array[i])
else:
lst.append(array[i])
# 取出现一次的集合跟出现多次的集合的差集
return (list(set(lst)-set(sec_lst)))
#题解#