Created
June 1, 2020 23:44
-
-
Save hkasera/e2d99637849a910cf80269e573233bd9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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