[LeetCode]#136 Single Number
1 min readMar 13, 2020
Environment: Python 3.7
Key technique: Hash Table, list .append and .move function
Example 1:
Input: [2,2,1]
Output: 1
Example 2:
Input: [4,1,2,1,2]
Output: 4
Analysis:
Find single number in given numbers.
Solution:
class Solution:
def singleNumber(self, nums: List[int]) -> int:
no_duplist=[]
ans=0
for i in nums:
if i not in no_duplist:
no_duplist.append(i)
else:
no_duplist.remove(i)
ans=no_duplist[0]
return ans
Submitted result:
Lesson learn:
Use function .append and .move
Reference: