解题思路:
- 还是hash方法,Python的字典能够很好的解决这件事情
- 用键值对来记录元素以及其出现的次数
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param array int整型一维数组
# @return int整型一维数组
#
class Solution:
def FindNumsAppearOnce(self , array: List[int]) -> List[int]:
# write code here
dic = {}
lst = []
for i in array:
if i not in dic:
dic[i] = 1
else:
dic[i] += 1
for k in dic:
if dic[k] < 2:
lst.append(k)
print(dic)
print(lst)
return sorted(lst)