Pergunta de entrevista da empresa eBay

Find all the pairs in array that add up to a certain number?

Resposta da entrevista

Sigiloso

23 de jan. de 2012

h = new HashMap(); for (int i=0; i < a.length; ++i) { h.put(a[i], i); } for (int i=0; i < h.keys.length; ++i) { int match = sum - h.keys[i]; if (h.get(match) != null) { print h.keys[i] + "," + h.keys[match]; } }