You are viewing a single comment's thread. Return to all comments →
public static List<Integer> matchingStrings(List<String> stringList, List<String> queries) { // Write your code here Map<String,Integer> map=new LinkedHashMap<>(); for(int i=0;i<stringList.size();i++){ if(map.containsKey(stringList.get(i))){ map.put(stringList.get(i), map.get(stringList.get(i))+1); }else{ map.put(stringList.get(i), 1); } } List<Integer> list=new ArrayList<>(); for(int i=0;i<queries.size();i++){ if( map.containsKey(queries.get(i))){ list.add(map.get(queries.get(i))); }else{ list.add(0); } } return list; }
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 Using Map