solution.md 1.0 KB
Newer Older
ToTensor's avatar
ToTensor 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
# 存在重复元素

<p>给定一个整数数组,判断是否存在重复元素。</p>

<p>如果存在一值在数组中出现至少两次,函数返回 <code>true</code> 。如果数组中每个元素都不相同,则返回 <code>false</code></p>

<p> </p>

<p><strong>示例 1:</strong></p>

<pre>
<strong>输入:</strong> [1,2,3,1]
<strong>输出:</strong> true</pre>

<p><strong>示例 2:</strong></p>

<pre>
<strong>输入: </strong>[1,2,3,4]
<strong>输出:</strong> false</pre>

<p><strong>示例 3:</strong></p>

<pre>
<strong>输入: </strong>[1,1,1,3,3,4,3,2,4,2]
<strong>输出:</strong> true</pre>


## template

```python
ToTensor's avatar
ToTensor 已提交
31 32 33 34 35 36 37 38 39 40
class Solution:
    def containsDuplicate(self, nums: List[int]) -> bool:

        nums.sort()
        count = 0
        while count < len(nums) - 1:
            if nums[count] == nums[count + 1]:
                return True
            count += 1
        return False
ToTensor's avatar
ToTensor 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

```

## 答案

```python

```

## 选项

### A

```python

```

### B

```python

```

### C

```python

```