Skip to content

Commit 217970b

Browse files
committed
solve(leetcode): 217. Contains Duplicate
1 parent 18e2843 commit 217970b

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# 217. Contains Duplicate
2+
3+
Given an integer array nums, return true if any value appears at least twice in the array, and return false if every
4+
element is distinct.
5+
6+
```
7+
Example 1:
8+
9+
Input: nums = [1,2,3,1]
10+
Output: true
11+
12+
Example 2:
13+
14+
Input: nums = [1,2,3,4]
15+
Output: false
16+
17+
Example 3:
18+
19+
Input: nums = [1,1,1,3,3,4,3,2,4,2]
20+
Output: true
21+
```
22+
23+
Constraints:
24+
25+
```
26+
1 <= nums.length <= 105
27+
-109 <= nums[i] <= 109
28+
```
29+
30+
[Problem link](https://leetcode.com/problems/contains-duplicate/)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module src
2+
3+
go 1.20
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package src
2+
3+
func ContainsDuplicate(nums []int) bool {
4+
uniqueNumbers := make(map[int]bool)
5+
for _, num := range nums {
6+
if _, ok := uniqueNumbers[num]; ok {
7+
return true
8+
} else {
9+
uniqueNumbers[num] = true
10+
}
11+
}
12+
13+
return false
14+
}

0 commit comments

Comments
 (0)