Short C# solution using Dictionary and Lambda Expression :)

  • 1
    public class Solution {
        public List<string> Anagrams(string[] strs) {
            var book = new Dictionary<string, List<string>>();
            foreach(var str in strs){
                var s = str.ToCharArray();
                var key = new string(s);
                if (!book.ContainsKey(key)){
                    book.Add(key, new List<string>());
            return book.Values.Where(v => v.Count > 1).SelectMany(i=>i).ToList();

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.