Last active
December 12, 2015 08:19
-
-
Save silverjam/4743301 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.util.*; | |
class Main | |
{ | |
public static void sumsTo(int nums[], int sum) | |
{ | |
HashMap<Integer, Integer> hash = new HashMap<Integer, Integer>(); | |
for(int num : nums) | |
hash.put(num, 1); | |
for(int x = 0; x < nums.length; x++) | |
{ | |
int y = sum - nums[x]; | |
if (hash.containsKey(y)) | |
System.out.println(nums[x] + " + " + y + " = " + sum); | |
} | |
} | |
public static void main(String args[]) | |
{ | |
sumsTo(new int[] { 1,2,3,4,5 }, 6 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment