给定一个单词列表,只返回可以使用在键盘同一行的字母打印出来的单词。键盘如下图所示。

示例:

输入: ["Hello", "Alaska", "Dad", "Peace"] 输出: ["Alaska", "Dad"]

注意:

  1. 你可以重复使用键盘上同一字符。
  2. 你可以假设输入的字符串将只包含字母。
class Solution {
public:
vector<string> findWords(vector<string>& words) {
map<char, int> check;
check['Q'] = 1;check['q'] = 1;
check['W'] = 1;check['w'] = 1;
check['E'] = 1;check['e'] = 1;
check['R'] = 1;check['r'] = 1;
check['T'] = 1;check['t'] = 1;
check['Y'] = 1;check['y'] = 1;
check['U'] = 1;check['u'] = 1;
check['I'] = 1;check['i'] = 1;
check['O'] = 1;check['o'] = 1;
check['P'] = 1;check['p'] = 1;
check['A'] = 2;check['a'] = 2;
check['S'] = 2;check['s'] = 2;
check['D'] = 2;check['d'] = 2;
check['F'] = 2;check['f'] = 2;
check['G'] = 2;check['g'] = 2;
check['H'] = 2;check['h'] = 2;
check['J'] = 2;check['j'] = 2;
check['K'] = 2;check['k'] = 2;
check['L'] = 2;check['l'] = 2;
check['Z'] = 3;check['z'] = 3;
check['X'] = 3;check['x'] = 3;
check['C'] = 3;check['c'] = 3;
check['V'] = 3;check['v'] = 3;
check['B'] = 3;check['b'] = 3;
check['N'] = 3;check['n'] = 3;
check['M'] = 3;check['m'] = 3;
vector<string> res;
int len = words.size();
for(int i = 0; i < len; i++)
{
int flag = true;
int temp = check[words[i][0]];
for(int j = 0; j < words[i].size(); j++)
{
if(check[words[i][j]] != temp)
{
flag =false;
break;
}
}
if(flag)
res.push_back(words[i]);
}
return res;
}
};

Leetcode500.Keyboard Row键盘行的更多相关文章

  1. [LeetCode] Keyboard Row 键盘行

    Given a List of words, return the words that can be typed using letters of alphabet on only one row' ...

  2. [LeetCode] 500. Keyboard Row 键盘行

    Given a List of words, return the words that can be typed using letters of alphabet on only one row' ...

  3. 500 Keyboard Row 键盘行

    给定一个单词列表,只返回可以使用在键盘同一行的字母打印出来的单词. 详见:https://leetcode.com/problems/keyboard-row/description/ C++: cl ...

  4. Leetcode#500. Keyboard Row(键盘行)

    题目描述 给定一个单词列表,只返回可以使用在键盘同一行的字母打印出来的单词.键盘如下图所示. 示例1: 输入: ["Hello", "Alaska", &quo ...

  5. 46. leetcode 500. Keyboard Row

    500. Keyboard Row Given a List of words, return the words that can be typed using letters of alphabe ...

  6. LeetCode 键盘行-Python3.7<四>

    500. 键盘行 题目网址:https://leetcode-cn.com/problems/keyboard-row/hints/ 给定一个单词列表,只返回可以使用在键盘同一行的字母打印出来的单词. ...

  7. LeetCode——Keyboard Row

    LeetCode--Keyboard Row Question Given a List of words, return the words that can be typed using lett ...

  8. [LeetCode] 651. 4 Keys Keyboard 四键的键盘

    Imagine you have a special keyboard with the following keys: Key 1: (A): Print one 'A' on screen. Ke ...

  9. Week4 - 500.Keyboard Row & 557.Reverse Words in a String III

    500.Keyboard Row & 557.Reverse Words in a String III 500.Keyboard Row Given a List of words, ret ...

随机推荐

  1. C# 封装首页、上一页、下一月、尾页处理器

    public void BtnPageClickEvent(object sender,string focusForeground,string lostFocusForeground) { But ...

  2. java笔试之简单密码

    密码是我们生活中非常重要的东东,我们的那么一点不能说的秘密就全靠它了.哇哈哈. 接下来渊子要在密码之上再加一套密码,虽然简单但也安全. 假设渊子原来一个BBS上的密码为zvbo9441987,为了方便 ...

  3. cmd以管理员打开

  4. C++ 系列:基础知识储备

    Copyright © 2000-2017, NORYES, All Rights Reserved. http://www.cnblogs.com/noryes/ ----------------- ...

  5. idea-----idea的项目中output框出现乱码

    找到tomcat的安装目录中的logging.properties 我的在这里:E:\tools\tomcat\apache-tomcat-8.5.38\conf 改其中的参数 修改前  java.u ...

  6. IDEA使用Maven+Tomcat插件实现热部署

    1 配置tomcat pom.xml <!-- tomcat7启动插件 --> <plugin> <groupId>org.apache.tomcat.maven& ...

  7. differential related impedance and termination

    Impedance (1) Z0 Z0 is the impedance of one T-line while other lines are held at 0. Single end. (2) ...

  8. Matlab系列作业

    (2019年2月19日注:Matlab这门课是在我大四上学期经历的,那时候开这篇文章是为了记录学习Matlab的时候遇到的坑,所以将所有的作业题合并到一篇文章中) 1.创建一个10*10的矩阵,矩阵所 ...

  9. CF #575 Div3

    // 比赛链接:https://codeforces.com/contest/1196 // CF 2019.7.24 // 本想Div3手速场上分,结果卡在C题,掉了不少分. // 自闭了这么久,今 ...

  10. 群晖系统下btfs(占用5%)和ext4文件格式的硬盘占用和选择

    1个人感觉选择ext4就可以,毕竟重要数据会设置raid1 不重要的数据也不需要快照什么的 商用除外 对于一个4t的硬盘 实际容量3726G 使用ext4可用空间3666G,群晖 占用60G大概1.6 ...