Concise C++ solution via string::find_first_not_of


  • 0
    A

    class Solution {
    public:
    vector<string> findWords(vector<string>& words) {
    string str1 = "qwertyuiopQWERTYUIOP";
    string str2 = "asdfghjklASDFGHJKL";
    string str3 = "zxcvbnmZXCVBNM";
    vector<string> ret;
    for (auto str: words)
    {
    if (str.find_first_not_of(str1) == string::npos ||
    str.find_first_not_of(str2) == string::npos ||
    str.find_first_not_of(str3) == string::npos)
    ret.push_back(str);
    }
    return ret;
    }
    };


Log in to reply
 

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