Skip to content

Commit 84e1fe9

Browse files
authored
Merge pull request #2029 from pastelto/main
[pastelto] WEEK 01 solutions
2 parents fce3f30 + ced3f8e commit 84e1fe9

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

contains-duplicate/pastelto.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
Return true when array contains duplicated number
3+
*/
4+
class Solution {
5+
public boolean containsDuplicate(int[] nums) {
6+
HashSet<Integer> set = new HashSet<>();
7+
8+
for (int num : nums) {
9+
if (set.contains(num)) return true;
10+
set.add(num);
11+
}
12+
return false;
13+
}
14+
}

two-sum/pastelto.java

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

0 commit comments

Comments
 (0)