Skip to content

Instantly share code, notes, and snippets.

@Desolve
Last active June 28, 2019 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Desolve/1b5deb87574dc16aa0a51d9a07a9fb2c to your computer and use it in GitHub Desktop.
Save Desolve/1b5deb87574dc16aa0a51d9a07a9fb2c to your computer and use it in GitHub Desktop.
0001 Two Sum
class Solution {
public int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
int complement = target - nums[i];
if(map.containsKey(complement)) {
return new int[] { map.get(complement), i};
}
map.put(nums[i], i);
}
throw new IllegalArgumentException("No Answer");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment