File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * 1 .๋ฌธ์ ์ ์
3+ * ๋ฐฐ์ด์ด ์ฃผ์ด์ง๋ฉด, ๋ฐฐ์ด์ ํฌํจ๋ ์ ์๊ฐ ์ค๋ณต์ด ์๋ค๋ฉด fasle, ์ ์ด๋ 1ํ ์ด์ ์ค๋ณต์ด ์๋ค๋ฉด true๋ฅผ ๋ฐํํด์ผํ๋ค.
4+ * ๋ฐฐ์ด์ ํฌ๊ธฐ๋?
5+ * - 1 <= length <= 100000
6+ * 2. naive algorithm ๋์ถ
7+ * - ๋ฐฐ์ด์ ํ์ํ๋ฉด์ Set์๋ฃ๊ตฌ์กฐ์ ๋ฃ๋๋ค. ์ด๋ Set์ ๋ฃ์ผ๋ ค๋ ๊ฐ์ด ์ด๋ฏธ ํฌํจ๋์ด์๋์ง๋ฅผ ํ์ธํฉ๋๋ค.. true๋ฅผ ๋ฐํ.
8+ * - ๋ฐฐ์ด ์ ์ฒด๋ฅผ ํ์ํ๋๋ฐ ํฌํจ์ฌ๋ถ์์ ๊ฑธ๋ฆฌ์ง ์์ผ๋ฉด false๋ฅผ ๋ฐํ
9+ * 3. ์๊ฐ&๊ณต๊ฐ๋ณต์ก๋ ๋ถ์
10+ * - ๋ฐฐ์ด์ ๊ธธ์ด๊ฐ N์ด๋ฉด O(N)์ ์๊ฐ ๋ณต์ก๋
11+ * 4. ์ฝ๋์์ฑ
12+ */
13+ import java .util .*;
14+ public class sangyyypark {
15+ public boolean containsDuplicate (int [] nums ) {
16+ Set <Integer > set = new HashSet <>();
17+ for (int i = 0 ; i < nums .length ; i ++) {
18+ int value = nums [i ];
19+ if (set .contains (value )) {
20+ return true ;
21+ }
22+ set .add (value );
23+ }
24+ return false ;
25+ }
26+ }
You canโt perform that action at this time.
0 commit comments