private HashMap<Integer, Integer> elements = new HashMap<Integer, Integer>();
public void add(int number) {
if (elements.containsKey(number)) {
elements.put(number, elements.get(number)+1);
} else {
elements.put(number, 1);
}
}
public boolean find(int target) {
for (int i : elements.keySet()) {
int remain = target - i;
if (elements.containsKey(remain)) {
if (i==remain && elements.get(remain)<2) {
continue;
}
return true;
}
}
return false;
}
No comments:
Post a Comment