You are viewing a single comment's thread. Return to all comments →
here is my java solution. short and sweet.
static void whatFlavors(int[] cost, int money) { Map<Integer,Integer> map = new HashMap<>(); map.put(money-cost[0],1); for(int i=1; i<cost.length; i++) { if(map.containsKey(cost[i])) { System.out.println(map.get(cost[i])+" "+(i+1)); break; } else if(!map.containsKey(cost[i])&&money-cost[i]>0) { map.put(money-cost[i], i+1); } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Hash Tables: Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
here is my java solution. short and sweet.