Skip to content

Commit f86c3e3

Browse files
authored
Merge pull request #2 from mkhuzaima/mkhuzaima-patch-1
Added Problem 1
2 parents fdce838 + 12551c3 commit f86c3e3

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

0001_Two_Sum.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// id: 1
2+
// Name: Two Sum
3+
// link: https://leetcode.com/problems/two-sum/
4+
// Difficulty: Easy
5+
6+
class Solution {
7+
public int[] twoSum(int[] nums, int target) {
8+
HashMap<Integer, Integer> map = new HashMap<>();
9+
10+
for (int i = 0; i < nums.length; i++) {
11+
if (map.containsKey(target-nums[i])) {
12+
return new int[] {map.get(target-nums[i]), i};
13+
}
14+
else {
15+
map.put(nums[i], i);
16+
}
17+
}
18+
return null;
19+
}
20+
}

0 commit comments

Comments
 (0)