You are viewing a single comment's thread. Return to all comments →
Same solution - even shorter
static void whatFlavors(int[] costs, int money) { Map<Integer, Integer> values = new HashMap(); for (int i = 0; i < costs.length; i++) { if (values.keySet().contains(money - costs[i])) { System.out.println(String.format("%s %s", values.get(money - costs[i]), i+1)); break; } values.put(costs[i], i+1); } }
Hash Tables: Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
Same solution - even shorter