---
# System prepended metadata

title: Leetcode 287. Find the Duplicate Number
tags: [Set, Leetcode]

---

## 題解

### 使用 set

```python=
class Solution:
    def findDuplicate(self, nums: List[int]) -> int:
        # Time complexity: O(n)
        # Space complexity: O(n)
        hashSet = set()
        for num in nums:
            if num in hashSet:
                return num
            else:
                hashSet.add(num)
```