Skip to content

Commit 6b81b75

Browse files
aQuaaQua
aQua
authored and
aQua
committed
217 finish
1 parent 18b02a9 commit 6b81b75

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Algorithms/0217.contains-duplicate/contains-duplicate.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package Problem0217
22

33
func containsDuplicate(nums []int) bool {
4+
// 利用 m 记录 nums 中的元素是否出现过
45
m := make(map[int]bool, len(nums))
5-
for i := 0; i < len(nums); i++ {
6-
if ok := m[nums[i]]; ok {
6+
for _, n := range nums {
7+
if m[n] {
78
return true
89
}
9-
m[nums[i]] = true
10+
m[n] = true
1011
}
1112

1213
return false

0 commit comments

Comments
 (0)