Skip to content

Instantly share code, notes, and snippets.

@hkasera
Created June 1, 2020 23:44
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 hkasera/e2d99637849a910cf80269e573233bd9 to your computer and use it in GitHub Desktop.
Save hkasera/e2d99637849a910cf80269e573233bd9 to your computer and use it in GitHub Desktop.
private boolean sumsToTarget(int[] arr, int k) {
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 two sum solution");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment