File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .util .*;
2+
3+ class Solution {
4+ public boolean containsDuplicate (int [] nums ) {
5+ /*
6+ * -- ํ์ด --
7+ * nums๋ฅผ ์ํํ๋ฉด์ HashSet์ ๋ฐ์ดํฐ๋ฅผ ๋ฃ์ด์ ์ค๋ณต๋์๋ ์ง ํ์ธํ๋ค.
8+ *
9+ * -- ์๊ฐ ๋ณต์ก๋ --
10+ * ๊ธธ์ด N์ธ nums๋ฅผ ์ํํ๋๋ฐ ๋ํ ์๊ฐ ๋ณต์ก๋ => O(N)
11+ * hashSet์ add์ ๋ํ ์๊ฐ ๋ณต์ก๋ => O(1)
12+ * ์ ์ฒด ์๊ฐ ๋ณต์ก๋ O(1)*O(N) =O(n)
13+ * ------------------------------------------
14+ *
15+ * -- ๊ณต๊ฐ ๋ณต์ก๋ --
16+ * ๊ธธ์ด N์ธ nums๋ฅผ ๋ฃ์ Hashset์ด ์์ด์ผ ํ๊ธฐ์ O(N)
17+ * -------------------------------------------
18+ */
19+
20+ // ์ค๋ณต์ ํ์ธํ ์ ์๋ set ์ ์ธ
21+ HashSet <Integer > hashSet = new HashSet <>();
22+
23+ for (int num : nums ) {
24+ // set์ ์๋ค๋ฉด
25+ if (!hashSet .add (num )) return true ;
26+ }
27+
28+ return false ;
29+ }
30+ }
You canโt perform that action at this time.
0 commit comments