You are viewing a single comment's thread. Return to all comments →
Java solution using HashMap:
public static List<Integer> matchingStrings(List<String> strings, List<String> queries) { Map<String, Integer> countMap = new HashMap<>(); for(String query : queries){ countMap.put(query, 0); } for(String str : strings){ if(countMap.containsKey(str)){ Integer count = countMap.get(str); countMap.put(str, count + 1); } } List<Integer> returnList = new ArrayList<>(); for(String query : queries){ returnList.add(countMap.get(query)); } return returnList; }
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 →
Java solution using HashMap: