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

示例:

输入: ["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. OdDbAttribute和OdDbAttributeDefinition是什么关系

    OdDbAttributeDefinition是定义,比如说是英文,是一个占位符: OdDbAttribute就是具体的东西,比如是abc

  2. iOS开发系列-iOS签名机制

    概述 想要了解iOS的签名机制需要有一定密码学有一定的了解.下面依次介绍的数据的加密解密.单向散列函数.数字签名.证书.iOS签名机制. 数据加密解密 在网络通信中想要防止数据被攻击者拦截,我们通常对 ...

  3. java、jsp导出excel功能备份

    问题踩坑: ajax请求不能下载文件 必须这样: <a href="/media">点击下载Excel</a> 或者 location.href = '/m ...

  4. 74CMS漏洞打包(从老博客转)

    引子 这套CMS是上个月中做的审计,总共找到几个后台漏洞,可后台getshell,一个逻辑漏洞可任意发短信,还有一个前台注入漏洞.不过发到了某平台上之后,审核又要求我提交利用的poc,所以懒得发去了, ...

  5. C++:多线程002

    https://blog.csdn.net/morewindows/article/details/7442333 程序描述:主线程启动10个子线程并将表示子线程序号的变量地址作为参数传递给子线程.子 ...

  6. Python-函数基础(2)

    目录 可变长参数 形参 实参 函数对象 函数嵌套 名称空间与作用域 名称空间 内置名称空间 局部名称空间 全局名称空间 执行顺序 搜索顺序 作用域 全局作用域 局部作用域 global nonloca ...

  7. Http协议之content

    用android 通过http协议提交数据至服务器 content的内容 代码如下: private static JSONObject connUpload(String baseUrl, Map& ...

  8. EF Code First数据库映射规则及配置

    EF Code First数据库映射规则主要包括以下方面: 1.表名及所有者映射 Data Annotation: 指定表名 1 using System.ComponentModel.DataAnn ...

  9. <爬虫>用正则爬取B站首页图片

    import re import requests headers = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Apple ...

  10. 在scrapy中过滤重复的数据

    当为了确保爬到的数据中没有重复的数据的时候,可以实现一个去重的item pipeline 增加构造器方法,在其中初始化用于对与书名的去重的集合 在process_item方法中,先取出item中要判断 ...