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

示例:
输入: ["Hello", "Alaska", "Dad", "Peace"] 输出: ["Alaska", "Dad"]
注意:
- 你可以重复使用键盘上同一字符。
- 你可以假设输入的字符串将只包含字母。
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键盘行的更多相关文章
- [LeetCode] Keyboard Row 键盘行
Given a List of words, return the words that can be typed using letters of alphabet on only one row' ...
- [LeetCode] 500. Keyboard Row 键盘行
Given a List of words, return the words that can be typed using letters of alphabet on only one row' ...
- 500 Keyboard Row 键盘行
给定一个单词列表,只返回可以使用在键盘同一行的字母打印出来的单词. 详见:https://leetcode.com/problems/keyboard-row/description/ C++: cl ...
- Leetcode#500. Keyboard Row(键盘行)
题目描述 给定一个单词列表,只返回可以使用在键盘同一行的字母打印出来的单词.键盘如下图所示. 示例1: 输入: ["Hello", "Alaska", &quo ...
- 46. leetcode 500. Keyboard Row
500. Keyboard Row Given a List of words, return the words that can be typed using letters of alphabe ...
- LeetCode 键盘行-Python3.7<四>
500. 键盘行 题目网址:https://leetcode-cn.com/problems/keyboard-row/hints/ 给定一个单词列表,只返回可以使用在键盘同一行的字母打印出来的单词. ...
- LeetCode——Keyboard Row
LeetCode--Keyboard Row Question Given a List of words, return the words that can be typed using lett ...
- [LeetCode] 651. 4 Keys Keyboard 四键的键盘
Imagine you have a special keyboard with the following keys: Key 1: (A): Print one 'A' on screen. Ke ...
- 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 ...
随机推荐
- SQLAlchemy的out join
我有一个app表,一个usergroup表,还有一个app_access_map表.用以实现对app访问的白名单控制. app和usergroup是多对多关系,app_access_map是中间表,不 ...
- stop slave->reset slave->start slave 复制从哪个位置开始?reset slave all呢?
reset slave首先来看下当前master-slave情况 mysql> prompt \u@\h,\p:\d>\_ PROMPT set to '\u@\h,\p:\d>\_ ...
- 3.在vm上安装centos 7
在vm上安装centos 7 1.文件 → 新建虚拟机 3.选择安装Linux系统 4. 虚拟机命名,并选择安装的文件夹 5.选择分配的处理器 6.使用网络地址转换 7.默写选项 9.新建虚拟机 10 ...
- Python全栈开发:选课系统实例
程序目录: bin文件夹下为可执行文件:administrator,students config文件夹下为设置文件,涉及系统参数配置:setting db文件夹为数据类文件,涉及系统的输入输出数据: ...
- Android开发 BottomNavigationView学习
前言 注意这个里介绍的是AndroidX的com.google.android.material.bottomnavigation.BottomNavigationView xml布局中 <co ...
- Rainbow的信号
Rainbow的信号 有一串长度为n的数列,现在从中等概率选出l,r,如果l大于r,则交换,有三个询问 l~r间的数与和的数学期望 l~r间的数或和的数学期望 l~r间的数异或和的数学期望 对于100 ...
- Java虚拟机性能管理神器 - VisualVM(7) 排查JAVA应用程序线程泄漏【转】
Java虚拟机性能管理神器 - VisualVM(7) 排查JAVA应用程序线程泄漏[转] 标签: javajvm线程泄漏 2015-03-11 19:47 1098人阅读 评论(0) 收藏 举报 ...
- DbUtils要点小结
一. DbUtils核心API 1. QueryRunner update方法 query方法 2. 各种Handler都实现ResultSetHandler接口 beanhandler beanli ...
- webpack打包指定HTML的文件并引入指定的chunks
1. 安装 html-webpack-plugin npm install html-webpack-plugin --save-dev 2. 在webpack.config.js中配置 const ...
- MS-coco数据集下载及使用(转)
先做个标记,改天研究下. 几个链接: MS coco数据集介绍及下载 Microsoft COCO 数据集 COCO Dataset 数据特点 COCO 数据集的使用