anonymus
BAN USER
Questions (1)
Comments (2)
Reputation 50
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
My solution:
static boolean hasGivenSum(int[] array, int sum) {
HashMap<Integer, Integer> hashMap = new HashMap<Integer, Integer>();
HashMap<Integer, Integer> hashMapIndexes = new HashMap<Integer, Integer>();
boolean response = false;
for(int i = 0; i < array.length; i++){
hashMap.put(i,sum - array[i]);
hashMapIndexes.put(array[i],i);
}
for(int i = 0; i < array.length; i++){
int rest = hashMap.get(i);
if(hashMapIndexes.containsKey(rest) && hashMapIndexes.get(rest) != i){
response = true;
break;
}
}
return response;
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
}
- anonymus January 19, 2017