|
| 1 | +#================================================== |
| 2 | +#==> Title: 136. 只出现一次的数字 |
| 3 | +#==> Author: Zhang zhen |
| 4 | +#==> Email: hustmatnoble.gmail.com |
| 5 | +#==> GitHub: https://github.com/MatNoble |
| 6 | +#==> Date: 2/22/2021 |
| 7 | +#================================================== |
| 8 | + |
| 9 | +from typing import List |
| 10 | +class Solution: |
| 11 | + def singleNumber(self, nums: List[int]) -> int: |
| 12 | + # from collections import Counter |
| 13 | + # return sorted(Counter(nums).items(),key=lambda x:x[1])[0][0] |
| 14 | + for num in nums[1:]: |
| 15 | + nums[0] ^= num |
| 16 | + return nums[0] |
| 17 | + |
| 18 | +mat = Solution() |
| 19 | +nums = [2,3,2,1,1] |
| 20 | +mat.singleNumber(nums) |
0 commit comments