Skip to content

Commit 512e1f1

Browse files
authored
Merge pull request #1701 from shinheekim/main
[shinheekim] WEEK 01 solutions
2 parents 5e35fcb + 59119e5 commit 512e1f1

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

contains-duplicate/shinheekim.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import java.util.HashSet;
2+
import java.util.Set;
3+
4+
class Solution {
5+
public boolean containsDuplicate(int[] nums) {
6+
Set<Integer> visited = new HashSet<>();
7+
8+
for (int n : nums){
9+
if (!visited.add(n)){
10+
return true;
11+
}
12+
}
13+
return false; // 모든 값이 고유할 때
14+
}
15+
}

two-sum/shinheekim.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public int[] twoSum(int[] nums, int target) {
3+
int[] result = new int[2];
4+
5+
for (int i = 0; i < nums.length; i++){
6+
for (int j = i + 1; j < nums.length; j++){
7+
if (nums[i] + nums[j] == target){
8+
result[0] = i;
9+
result[1] = j;
10+
return result;
11+
}
12+
}
13+
}
14+
return null;
15+
}
16+
}

0 commit comments

Comments
 (0)