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

示例:

输入: ["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. 炮兵阵地 /// 状压DP oj26314

    题目大意: 炮兵阵地 设置炮兵的位置 其上两位 下两位 左两位 右两位 不能同时设置炮兵 这题是 corn fields玉米地 的升级版 可以先看下这题的注释 更详细些 第一种方法是网上大多数题解的解 ...

  2. 2019-8-2-WPF-依赖属性绑定不上调试方法

    title author date CreateTime categories WPF 依赖属性绑定不上调试方法 lindexi 2019-08-02 19:56:32 +0800 2019-8-2 ...

  3. UMP系统架构 Zookeeper

  4. Widget Factory

    Widget Factory 有N种零件,生产所需天数都为3~9天,有M条记录,记录开工星期几,和停工星期几,并告诉你这条记录所加工的零件,求每种零件的生产时间,\(1≤N,M≤300\). 解 显然 ...

  5. dea死锁处理和大事务处理

    死锁处理流程: show full processlist; # 获得当前所有数据库连接 select id, db, user, host, command, time, state, info f ...

  6. [ javasript ] javascript中的each遍历!

    1.数组中的each var arr = [ "one", "two", "three", "four"]; $.eac ...

  7. springboot thymeleaf ----服务端渲染html

    一. 引用命名空间 <html xmlns:th="http://www.thymeleaf.org"> 不这么写 html标签没闭合会报错 二.实际内容在../sta ...

  8. JSON高亮格式化页面显示

    高亮CSS定义: <style type="text/css"> pre {outline: 1px solid #ccc; padding: 5px; margin: ...

  9. line-height影响排版

    父级div设置了line-height值,子级div会继承line-height.如果不想子级元素继承,给子级元素设置line-height:normal.

  10. 牛客NOIP暑期七天营-TG3 赛后题解

    目录 牛客NOIP暑期七天营-提高组3 A-破碎的矩阵 题目描述 link 题解 代码 B-点与面 题目描述 link 题解 代码 C-信息传递 题目描述 link 题解 牛客NOIP暑期七天营-提高 ...