题目描述、样例及注意事项:
Given a List of words, return the words that can be typed using letters of alphabet on only one row’s of American keyboard like the image below.
Example 1:
Input: [“Hello”, “Alaska”, “Dad”, “Peace”]
Output: [“Alaska”, “Dad”]
Note:
You may use one character in the keyboard more than once.
You may assume the input string will only contain letters of alphabet.
原题链接:https://leetcode.com/problems/keyboard-row/description/
这道题目要求判断输入的字符串中,各字母是否位于键盘上的同一行。参考别人的做法,思路为设置3种状态变量(字母分布在键盘上共三行)001、010、100,判断输入的字符串所属的状态值,并和111进行与(&)操作,若结果为0,则该字符串各字母不在同一行上。具体代码实现如下
class Solution {
public: