Pergunta de entrevista da empresa Wallet Hub

find two elements in the array which produce a sum equals to a specific target sum

Resposta da entrevista

Sigiloso

28 de jun. de 2017

there are plenty of ready made solutions in the Internet, but here is one of them public static int[] method(int[] nums, int target) { Map map = new HashMap(); for (int i = 0; i < nums.length; i++) { int complement = target - nums[i]; if (map.containsKey(complement)) { return new int[]{map.get(complement), i}; } map.put(nums[i], i); } throw new IllegalArgumentException(); }