You are viewing a single comment's thread. Return to all comments →
Some of your statements can be omitted, namely the initial put in the map and the second check if the map does not contain the key, like so:
static void whatFlavors(int[] cost, int money) { Map<Integer,Integer> map = new HashMap<>(); for(int i=0; i<cost.length; i++) { if(map.containsKey(cost[i])) { System.out.println(map.get(cost[i])+" "+(i+1)); break; } else 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 →
Some of your statements can be omitted, namely the initial put in the map and the second check if the map does not contain the key, like so: