File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ [λ¬Έμ νμ΄]
3
+ time: O(N), space: O(N)
4
+ - κ°μ μκ° νλλΌλ μμΌλ©΄ true
5
+ - λͺ¨λ μκ° λ€λ₯΄λ©΄ false
6
+
7
+ [νκ³ ]
8
+ ArrayList vs Set
9
+ ArrayList: O(N^2), λ§€λ² λ¦¬μ€νΈλ₯Ό μ²μλΆν° κ²μν΄μΌ νλ©°, nλ² λ°λ³΅
10
+ Set : O(N) , λ΄λΆμ μΌλ‘ ν΄μ ν
μ΄λΈμ μ¬μ©νμ¬ μ€λ³΅ νμΈμ O(1)μ μν
11
+ λ°λΌμ μ€λ³΅ κ²μ¬μμ Set λ ν¨μ¨μ
12
+
13
+ set.add()μ return μλ£νμ boolean μ΄λ€.
14
+ μ΄νμλ if(!set.add()) μ²λΌ μ¬μ©ν΄λ μ’μ λ―.
15
+ */
16
+ class Solution {
17
+ public boolean containsDuplicate (int [] nums ) {
18
+ Set <Integer > set = new HashSet <>();
19
+ for (int num : nums ) {
20
+ if (set .contains (num )) {
21
+ return true ;
22
+ }
23
+ set .add (num );
24
+ }
25
+ return false ;
26
+ }
27
+ }
You canβt perform that action at this time.
0 commit comments