题解 | 数组中只出现一次的两个数字
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param nums int整型一维数组 # @return int整型一维数组 # class Solution: def FindNumsAppearOnce(self , nums ): # write code here map={} for num in nums : if num in map : map.pop(num) else : map[num]=1 key= map.keys() return sorted(key) 本次学习到的新知识点:map.pop(key), 可以删除map 中key 为key 键值对 key=map.keys() 可以获得map 中全部的keys sorted(map) 可以将map 排序,默认从小到大排序 sorted(map,reverse = True) 可以从大到小