Created
April 10, 2017 16:19
-
-
Save dennermiranda/4e644345d9e6830a3a58819d551fd2c2 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
import java.util.HashMap; | |
public class Interview { | |
public static boolean sum(int[] A, int b){ | |
HashMap<Integer, Integer> hash = new HashMap<Integer, Integer>(); | |
for (int i = 0; i<A.length; i++){ | |
hash.put(A[i], i); | |
} | |
for (int i = 0; i<A.length; i++){ | |
if(hash.get(b-A[i])!= null && hash.get(b-A[i]) != i){ | |
return true; | |
} | |
} | |
return false; | |
} | |
public static void main(String[] args) { | |
int [] A = {2, 2, 2, 2, 1, 2, 1, 2, 1, 3}; | |
System.out.println(sum(A, 200)); | |
System.out.println(sum(A, 4)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment