C# 1-Line Linq Solution


  • 0
    M
        public string[] FindWords(string[] words) {
            return words
                .Select(word => new { Word = word, Upper = word.ToUpper() })
                .Where(word => 
                       word.Upper.All(a=>"QWERTYUIOP".Contains(a)) || 
                       word.Upper.All(a=>"ASDFGHJKL".Contains(a)) || 
                       word.Upper.All(a=>"ZXCVBNM".Contains(a)))
                .Select(word => word.Word)
                .ToArray();
        }
    }

Log in to reply
 

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