c++ straight forward solution


  • 0
    B
    class Solution {
        int row[26] = { 1, 2, 2, 1, 0, 1, 1, 1, 0, 1, 1, 1, 2, 2, 0, 0, 0, 0, 1, 0, 0, 2, 0, 2, 0, 2 };
        
        bool check(string word) {
            int val = row[tolower(word[0]) - 'a'];
            for(char c : word) if(row[tolower(c) - 'a'] != val) return false;
            return true;
        }
    public:
        vector<string> findWords(vector<string>& words) {
            vector<string> found;
            for(string& w : words) if(check(w)) found.push_back(w);
            return found;
        }
    };
    

Log in to reply
 

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