c++ solution


  • 0
    I
    public:
        vector<string> findWords(vector<string>& words) {
           vector<string> ans;
            map<char,int> firs;
            map<char,int> seco;
            map<char,int> thir;
            firs['q']=1;
                firs['w']=1;
            firs['e']=1;
                firs['r']=1;
            firs['t']=1;
                firs['y']=1;
            firs['u']=1;
                firs['i']=1;
            firs['o']=1;
                firs['p']=1;
            seco['a']=1;
            seco['s']=1;
             seco['d']=1;
            seco['f']=1;
             seco['g']=1;
            seco['h']=1;
             seco['j']=1;
            seco['k']=1;
             seco['l']=1;
            thir['z']=1;
            thir['x']=1;
            thir['c']=1;
            thir['v']=1;
            thir['b']=1;
            thir['n']=1;
            thir['m']=1;
                   firs['Q']=1;
                firs['W']=1;
            firs['E']=1;
                firs['R']=1;
            firs['T']=1;
                firs['Y']=1;
            firs['U']=1;
                firs['I']=1;
            firs['O']=1;
                firs['P']=1;
            seco['A']=1;
            seco['S']=1;
             seco['D']=1;
            seco['F']=1;
             seco['G']=1;
            seco['H']=1;
             seco['J']=1;
            seco['K']=1;
             seco['L']=1;
            thir['Z']=1;
            thir['X']=1;
            thir['C']=1;
            thir['V']=1;
            thir['B']=1;
            thir['N']=1;
            thir['M']=1;
        for(int i=0;i<words.size();i++)
        {
            int i1;
    int len=words[i].length();
            for( i1=0;i1<len;i1++)
            {
                if(firs.find(words[i][i1])==firs.end())
                    break;
                
            }
            if(i1==len)
                ans.push_back(words[i]);
            for( i1=0;i1<len;i1++)
            {
                if(seco.find(words[i][i1])==seco.end())
                    break;
                
            }
            if(i1==len)
                ans.push_back(words[i]);
            for( i1=0;i1<len;i1++)
            {
                if(thir.find(words[i][i1])==thir.end())
                    break;
                
            }
            if(i1==len)
                ans.push_back(words[i]);
        
        
        
        
        
        
        
        
        
        }
        
        
        return ans;
        
        }
    };```

Log in to reply
 

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