You are viewing a single comment's thread. Return to all comments →
This is my code in Java 8, I've presented the snippet of the concerned method, hope this helps. Here you go..
static int[] matchingStrings(String[] strings, String[] queries) { Map<String, Integer> map = new HashMap<>(); for (String string : strings) { if (!map.containsKey(string)) map.put(string, 1); else { int count = map.get(string); map.put(string, ++count); } } int[] array = new int[queries.length]; int count = 0; for (String string : queries) { if (map.containsKey(string)) array[count++] = map.get(string); else count++; } return array; }
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 →
This is my code in Java 8, I've presented the snippet of the concerned method, hope this helps. Here you go..