C# solution use rownum array


  • 0
    T
    public class Solution {
        public string[] FindWords(string[] words) {
            int [] map = {2,3,3,2,1,2,2,2,1,2,2,2,3,3,1,1,1,1,2,1,1,3,1,3,1,3};
            List<String> result= new List<String>();
            foreach(var word in words)
            {
                var lowWord = word.ToLower();
                var row = map[lowWord[0]-'a'];
                var isSameRow=true;
                foreach( var letter in lowWord )
                {
                    if(row!=map[letter-'a'])
                    {
                        isSameRow=false;
                        break;
                    }
                }
                if(isSameRow)
                {
                    result.Add(word);
                }
            }
            
            return result.ToArray();
            
        }
    }
    

Log in to reply
 

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