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 ...
随机推荐
- <Python基础>字符串的基本操作
s = 'abCDeFg aBcDea' print(s.find('b')) #通过元素查找索引,找不到返回-1 print(s.index('b')) #通过元素查找索引,找不到报错(会报错,基本 ...
- C# IP正则表达式
public static bool IsValidIp(string strIn) { bool b = Regex.IsMatch(strIn, @"^[0-9]{1,3}\.[0-9] ...
- 测试环境添加spark parcel 2.1步骤
1.先到http://archive.cloudera.com/spark2/parcels/2.1.0.cloudera1/ 下载需要的文件比如我linux版本需要是6的 hadoop6需要下载这些 ...
- (转)Lua语言实现简单的多线程模型
转自: https://blog.csdn.net/john_crash/article/details/49489609 lua本身是不支持真正的多线程的,但是lua提供了相应的机制来实现多线程.l ...
- (转)线程池 ExecutorService 详细介绍以及注意点区别
线程池 ExecutorService 相信java开发都用到,这里做个简单笔记 一 Java通过Executors提供四种线程池,分别为: newCachedThreadPool创建一个可缓存线程池 ...
- OpenGL 鼠标交互响应事件
OpenGL 鼠标.键盘交互响应事件 先来一个样例: uses gl,glu,glut; procedure InitEnvironment;cdecl; begin glClearColor();/ ...
- Python全栈开发:web框架之tornado
概述 Tornado 是 FriendFeed 使用的可扩展的非阻塞式 web 服务器及其相关工具的开源版本.这个 Web 框架看起来有些像web.py 或者 Google 的 webapp,不过为了 ...
- 【daydayup】ceshuChat
时时当勉励,岁月不待人.珍惜时间伐~ 先看看项目运行的效果 这个是在本地环境打开了两个8080端口进行模拟运行的. 先放下作者的开源地址:https://github.com/ceshu/ceshuC ...
- BOM相关知识点
1.BOM概念:Browser Object Model 浏览器对象模型作用:提供了使用JS操作浏览器的接口 2.BOM包含了许多对象信息,包括如下这些:(1)screen 屏幕信息(2)locati ...
- html-圣杯布局
1.两边固定 当中自适应 2.当中列要完整显示 3.当中列要优先加载 浮动: 搭建完整的布局框架 margin 为赋值:调整旁边两列的位置(使三列布局到一行上) 使用相对定位:调整旁边两列的位置(使两 ...