<p>Given an array of strings <code>words</code>, return <em>the words that can be typed using letters of the alphabet on only one row of American keyboard like the image below</em>.</p>

<p>In the <strong>American keyboard</strong>:</p>

<ul>
	<li>the first row consists of the characters <code>&quot;qwertyuiop&quot;</code>,</li>
	<li>the second row consists of the characters <code>&quot;asdfghjkl&quot;</code>, and</li>
	<li>the third row consists of the characters <code>&quot;zxcvbnm&quot;</code>.</li>
</ul>
<img alt="" src="https://assets.leetcode.com/uploads/2018/10/12/keyboard.png" style="width: 800px; max-width: 600px; height: 267px;" />
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> words = [&quot;Hello&quot;,&quot;Alaska&quot;,&quot;Dad&quot;,&quot;Peace&quot;]
<strong>Output:</strong> [&quot;Alaska&quot;,&quot;Dad&quot;]
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> words = [&quot;omk&quot;]
<strong>Output:</strong> []
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> words = [&quot;adsdf&quot;,&quot;sfd&quot;]
<strong>Output:</strong> [&quot;adsdf&quot;,&quot;sfd&quot;]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= words.length &lt;= 20</code></li>
	<li><code>1 &lt;= words[i].length &lt;= 100</code></li>
	<li><code>words[i]</code> consists of English letters (both lowercase and uppercase).&nbsp;</li>
</ul>

class Solution {
public:
    vector<string> findWords(vector<string>& words) {
        vector<string> result;
        for(int i=0;i<words.size();i++){
            if(words[i].size()==1){
                result.push_back(words[i]);
            }
            else if(row1(words[i][0])){
                for(int j=1;j<words[i].size();j++){
                    if(!row1(words[i][j])){
                        break;
                    }
                    if(j==words[i].size()-1){
                        result.push_back(words[i]);
                    }
                }
            }
            else if(row2(words[i][0])){
                for(int j=1;j<words[i].size();j++){
                    if(!row2(words[i][j])){
                        break;
                    }
                    if(j==words[i].size()-1){
                        result.push_back(words[i]);
                    }
                }
            }
            else{
                for(int j=1;j<words[i].size();j++){
                    if(!row3(words[i][j])){
                        break;
                    }
                    if(j==words[i].size()-1){
                        result.push_back(words[i]);
                    }
                }
            }
        }
        return result;
    }

    bool row1(char C){
        char c = tolower(C);
        return (c=='q'||c=='w'||c=='e'||c=='r'||c=='t'||c=='y'||c=='u'||c=='i'||c=='o'||c=='p');
    }
    bool row2(char C){
        char c = tolower(C);
        return (c=='a'||c=='s'||c=='d'||c=='f'||c=='g'||c=='h'||c=='j'||c=='k'||c=='l');
    }
    bool row3(char C){
        char c = tolower(C);
        return (c=='z'||c=='x'||c=='c'||c=='v'||c=='b'||c=='n'||c=='m');
    }
};
8300