LeetCode六月挑战(6.22 )Single Number II LeetCode 137解题方案
Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
1 | Example 1: |
思路
将 数组中的数据放入Set中,然后让Set中的元素都出现三次,然后减去nums中元素的总和,这样,最后的结果为两倍数组中只出现一次的元素,最后返回1/2的结果即可。
代码
1 | class Solution: |