> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Contains Duplicate Python Solution with Tests

> Tested Python solution for LeetCode 217 with 12 pytest cases. Generate a practice environment with lcpy.

LeetCode 217, [Easy](https://leetcode-py.wisl.dev/catalog/easy.md). Topics: [Array](https://leetcode-py.wisl.dev/catalog/topics/array), [Hash Table](https://leetcode-py.wisl.dev/catalog/topics/hash-table), [Sorting](https://leetcode-py.wisl.dev/catalog/topics/sorting). [View on LeetCode](https://leetcode.com/problems/contains-duplicate/description/).

Generate this problem as a practice environment: tested reference solution, 12 [parametrized pytest cases](https://leetcode-py.wisl.dev/practice/testing.md), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 217   # by problem number
lcpy gen -s contains_duplicate   # by problem name
```

## Problem

Given an integer array `nums`, return `true` if any value appears **at least twice** in the array, and return `false` if every element is distinct.

### Examples

```
Input: nums = [1,2,3,1]
Output: true
```

**Explanation:** The element 1 occurs at the indices 0 and 3.

```
Input: nums = [1,2,3,4]
Output: false
```

**Explanation:** All elements are distinct.

```
Input: nums = [1,1,1,3,3,4,3,2,4,2]
Output: true
```

### Constraints

* 1 \<= nums.length \<= 10^5
* -10^9 \<= nums\[i] \<= 10^9

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/contains_duplicate/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/contains_duplicate/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(n)
    # Space: O(n)
    def contains_duplicate(self, nums: list[int]) -> bool:
        seen = set()
        for num in nums:
            if num in seen:
                return True
            seen.add(num)
        return False
```

## Complexity

| Time | Space |
| - | - |
| O(n) | O(n) |

## Tags

[Grind 75](https://leetcode-py.wisl.dev/catalog/grind-75.md), [Grind](https://leetcode-py.wisl.dev/catalog/grind.md), [Blind 75](https://leetcode-py.wisl.dev/catalog/blind-75.md), [NeetCode 150](https://leetcode-py.wisl.dev/catalog/neetcode-150.md), [NeetCode 250](https://leetcode-py.wisl.dev/catalog/neetcode-250.md), [NeetCode All](https://leetcode-py.wisl.dev/catalog/neetcode.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.