You are viewing a single comment's thread. Return to all comments →
C#
public static List<int> matchingStrings(List<string> stringList, List<string> queries) { List<int> result = []; Dictionary<string, int> stringListLookup = new(); for (int i = 0; i < stringList.Count; i++) { string s = stringList[i]; if(!stringListLookup.TryAdd(s, 1)) { stringListLookup[s] = stringListLookup[s] + 1; } } for (int j = 0; j < queries.Count; j++) { int count = 0; stringListLookup.TryGetValue(queries[j], out count); result.Add(count); } 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 →
C#