You are viewing a single comment's thread. Return to all comments →
// Java public static void checkMagazine(List<String> magazine, List<String> note) { Map<String, Integer> magazineMap = new HashMap<>(); Map<String, Integer> noteMap = new HashMap<>(); for(String m : magazine){ magazineMap.put(m, magazineMap.getOrDefault(m, 0)+1); } for(String n : note){ noteMap.put(n, noteMap.getOrDefault(n, 0)+1); } for (Map.Entry<String, Integer> entry : noteMap.entrySet()) { if (magazineMap.getOrDefault(entry.getKey(), 0) < entry.getValue()) { System.out.println("No"); return; } } System.out.println("Yes"); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Hash Tables: Ransom Note
You are viewing a single comment's thread. Return to all comments →