---
title: "#136 Single Number"
tags: LeetCode, Top100
---
#136. Single Number
題目描述
--
Given a **non-empty** array of integers ==nums==, every element appears twice except for one. Find that single one.
**Follow up**: Could you implement a solution with a linear runtime complexity and without using extra memory?
Example 1:
--
>Input: nums = [4,1,2,1,2]
Output: 4
解題思維
--
裡用只會有獨立一個,且重複一次的特性。將Input變成集合再\*2,減掉Input。
Math
--
```python=
class Solution:
def singleNumber(self, nums: List[int]) -> int:
return 2 * sum(set(nums)) - sum(nums)
```