C# solution


  • 0
    public class Solution {
        public string[] FindWords(string[] words) {
            
            string[] top = new string [10] {"q", "w", "e", "r","t","y","u","i","o","p"};
            string[] mid = new string [9] {"a","s","d","f","g","h","j","k","l"};
            string[] bot = new string [7] {"z","x","c","v","b","n","m"};
            
            List<string> results = new List<string>();
            foreach(string word in words)
            {
                if(Check(word, top) || Check(word, mid) || Check(word, bot))
                {
                    results.Add(word);
                }
            }
            
            return results.ToArray();
        }
        
        public bool Check(string word, string[] row)
        {
            for(int i =0;i<word.Length;i++)
            {
                if (!row.Contains(word[i].ToString().ToLower()))
                {
                    return false;
                }
            }
            
            return true;
        }
    }
    

Log in to reply
 

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