Skip to content

Commit df78dc2

Browse files
committed
WEEK 1 Solutions
1 parent 52e77d9 commit df78dc2

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
3+
// 첫번째 풀이
4+
class Solution {
5+
public boolean containsDuplicate(int[] nums) {
6+
for (int i=0; i < nums.length; i++) {
7+
for (int j=i+1; j < nums.length; j++) {
8+
if (nums[i] == nums[j]) return true;
9+
}
10+
}
11+
return false;
12+
}
13+
}
14+
15+
// 두번째 풀이
16+
class Solution {
17+
public boolean containsDuplicate(int[] nums) {
18+
Set set = new HashSet<Integer>();
19+
for (int i=0; i < nums.length; i++) {
20+
set.add(nums[i]);
21+
}
22+
23+
if (set.size() != nums.length) return true;
24+
return false;
25+
}
26+
}
27+
28+
*/
29+
30+
class Solution {
31+
public boolean containsDuplicate(int[] nums) {
32+
Set<Integer> set = new HashSet<>();
33+
for (int i=0; i < nums.length; i++) {
34+
if (!set.add(nums[i])) return true;
35+
}
36+
return false;
37+
}
38+
}

0 commit comments

Comments
 (0)