题目:找出数组中两个唯一出现一次的元素,其余元素均出现两次。
例子:
复制代码
1
2Input: [1,2,1,3,2,5] Output: [3,5]
代码:
复制代码
1
2
3
4
5
6
7
8
9
10
11class Solution: def func(self , nums): res = [] for i in nums: if i not in res:res.append(i) else:res.pop(res.index(i)) return res a = [1,2,1,3,2,5] s = Solution() print(s.func(a))
输出:
[3,5]
最后
以上就是鲜艳斑马最近收集整理的关于剑指offer-python:55.数组中只出现一次的两个数字的全部内容,更多相关剑指offer-python:55.数组中只出现一次内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复