Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions 0001_Two_Sum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// id: 1
// Name: Two Sum
// link: https://leetcode.com/problems/two-sum/
// Difficulty: Easy

class Solution {
public int[] twoSum(int[] nums, int target) {
HashMap<Integer, Integer> map = new HashMap<>();

for (int i = 0; i < nums.length; i++) {
if (map.containsKey(target-nums[i])) {
return new int[] {map.get(target-nums[i]), i};
}
else {
map.put(nums[i], i);
}
}
return null;
}
}