You are viewing a single comment's thread. Return to all comments →
Instead of count++ i guess we can use getOrDefault
static int[] matchingStrings(String[] strings, String[] queries) { int[] result = new int[queries.length]; Map<String, Integer> hm = new HashMap<>(); for (String str : strings) { hm.put(str, hm.getOrDefault(str, 0)+1); } for (int i=0; i<queries.length; i++) { result[i] = hm.getOrDefault(queries[i], 0); } return result; }
Seems like cookies are disabled on this browser, please enable them to open this website
Sparse Arrays
You are viewing a single comment's thread. Return to all comments →
Instead of count++ i guess we can use getOrDefault