0%

[筆記] Leetcode - 136. Single Number

https://leetcode.com/problems/single-number/

Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.
You must implement a solution with a linear runtime complexity and use only constant extra space.

1
2
3
4
5
6
7
8
9
class Solution:
def singleNumber(self, nums: List[int]) -> int:
list = []
for i in nums:
if i in list:
list.remove(i)
else:
list.append(i)
return list.pop()