We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 8e55614 + 2bb9fb8 commit dd891b6Copy full SHA for dd891b6
โcontains-duplicate/bus710.goโ
@@ -0,0 +1,21 @@
1
+// ์ฃผ์ด์ง ๋ฐฐ์ด์ ์ ํ ์ํ ํ๋ฏ๋ก, ์๊ฐ ๋ณต์ก๋์ ๊ณต๊ฐ ๋ณต์ก๋ ๋ชจ๋ O(n)์ผ ๊ฒ์ผ๋ก ์๊ฐํฉ๋๋ค.
2
+
3
+package week01
4
5
+// ์ฃผ์ด์ง ๋ฐฐ์ด nums๋ฅผ ์ํํ๋ฉฐ ์ค๋นํ ๋งต์ ํ์๋ฅผ ํ๋,
6
+// - ํค๊ฐ์ ํด๋นํ๋ ๊ฐ์ด ์์ผ๋ฉด ๋งต์ ํด๋น ํค๊ฐ์ true๋ฅผ ์ ์ฅํ๊ณ
7
+// - ํค๊ฐ์ ํด๋นํ๋ ๊ฐ์ด ์์ผ๋ฉด ์ฆ์ true๋ฅผ ๋ฐํ.
8
+// - ์ํ ํ์๋ ๋ฐํํ์ง ์์ ๊ฒฝ์ฐ ์ค๋ณต์ด ๋ฐ๊ฒฌ๋์ง ์์์ผ๋ฏ๋ก false๋ฅผ ๋ฐํ.
9
+func containsDuplicate(nums []int) bool {
10
+ dup := make(map[int]bool, 0)
11
+ for _, n := range nums {
12
+ if _, ok := dup[n]; !ok {
13
+ dup[n] = true
14
+ } else {
15
+ return true
16
+ }
17
18
19
+ return false
20
+}
21
0 commit comments