C++ 0ms clean solution


  • 0
     vector<string> findWords(vector<string>& words) {
            string row1="qwertyuiop";
            string row2="asdfghjkl";
            string row3="zxcvbnm";
            unordered_map<char,int>m(26);
            for(char c:row1) m[c]=1;
            for(char c:row2) m[c]=2;
            for(char c:row3) m[c]=3;
            for(int i=0;i<words.size();i++){
                int mark=m[tolower(words[i][0])];
                for(int j=1;j<words[i].size();j++){
                    if(m[tolower(words[i][j])]!=mark){
                        words.erase(words.begin()+i);
                        i--;
                        break;
                    }
                }
            }
            return words;
        }
    

Log in to reply
 

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