Skip to content

Instantly share code, notes, and snippets.

@riyafa
Created June 27, 2021 16:53
Show Gist options
  • Save riyafa/da8acdf28f92523d2c07565342506355 to your computer and use it in GitHub Desktop.
Save riyafa/da8acdf28f92523d2c07565342506355 to your computer and use it in GitHub Desktop.
class Solution {
public int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> map = new HashMap<>();
for(int i = 0; i < nums.length; i++) {
int num = nums[i];
if(map.containsKey(num)) {
return new int[]{i, map.get(num)};
} else {
map.put(target - num, i);
}
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment