500 Keyboard Row 键盘行
给定一个单词列表,只返回可以使用在键盘同一行的字母打印出来的单词。
详见:https://leetcode.com/problems/keyboard-row/description/
C++:
class Solution {
public:
vector<string> findWords(vector<string>& words)
{
vector<string> res;
unordered_set<char> row1{'q','w','e','r','t','y','u','i','o','p'};
unordered_set<char> row2{'a','s','d','f','g','h','j','k','l'};
unordered_set<char> row3{'z','x','c','v','b','n','m'};
for (string word : words)
{
int one = 0, two = 0, three = 0;
for (char c : word)
{
if (c < 'a')
{
c += 32;
}
if (row1.count(c))
{
one = 1;
}
if (row2.count(c))
{
two = 1;
}
if (row3.count(c))
{
three = 1;
}
if (one + two + three > 1)
{
break;
}
}
if (one + two + three == 1)
{
res.push_back(word);
}
}
return res;
}
};
参考:http://www.cnblogs.com/grandyang/p/6421749.html
500 Keyboard 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' ...
- [LeetCode] Keyboard Row 键盘行
Given a List of words, return the words that can be typed using letters of alphabet on only one row' ...
- Leetcode500.Keyboard Row键盘行
给定一个单词列表,只返回可以使用在键盘同一行的字母打印出来的单词.键盘如下图所示. 示例: 输入: ["Hello", "Alaska", "Dad& ...
- 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 ...
- 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 ...
- 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
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 ...
随机推荐
- iptables apache2
Apache2 iptables 安装指令:sudo apt-get install apache2 2.产生的启动和停止文件是:/etc/init.d/apache2 3.启动:sudo apach ...
- bash exec
1 当exec执行命令时,会为该命令创建shell进程,并且终止老的shell进程的执行,并且保留老的shell进程的进程号 [root@localhost ~]# cat test_exec.sh ...
- Marking as slave lost.
Spark on Yarn提交任务时报ClosedChannelException解决方案_服务器应用_Linux公社-Linux系统门户网站 http://www.linuxidc.com/Linu ...
- C++文件IO操作的简单示例
CppIODemo1.cpp #include <iostream> #include <fstream> #include <chrono> #define IN ...
- CH 5402 选课(分组背包+树形DP)
CH 5402 选课 \(solution:\) 很有讨论套路的一道题,利用树的结构来表示出不同课程之间的包含关系(这里还要建一个虚点将森林变成一颗打大树).然后用子树这个概念巧妙的消除了因为这些包含 ...
- 在U-Boot中添加自定义命令以实现自动下载程序【转】
本文转载自:https://gaomf.cn/2016/06/26/%E5%9C%A8U-Boot%E4%B8%AD%E6%B7%BB%E5%8A%A0%E8%87%AA%E5%AE%9A%E4%B9 ...
- 使用PHP对word文档进行操作的方法
使用php时,因为加密等原因,如果直接用FILE后者OPEN等函数读取WORD的话往往是乱码,原来要使用COM 这是我简单的一个读取并存储到新的WORD上的文件<? // 建立一个指向新COM组 ...
- 贪吃蛇小游戏—C++、Opencv编写实现
贪吃蛇游戏,C++.Opencv实现 设计思路: 1.显示初始画面,蛇头box初始位置为中心,食物box位置随机 2.按随机方向移动蛇头,按a.s.d.w键控制移动方向,分别为向左,向下,向右,向上 ...
- Autolayout UIScrollView
http://www.cocoachina.com/ios/20141011/9871.html Xcode6中如何对scrollview进行自动布局(autolayout) Xcode6中极大的 ...
- UIAlterController 的使用
相对于IOS8.4之后苹果对提示框做了进一步的封装,这将与之前的提示框有很大的同. 之前的 UIAlterView 是弹出一个提示框. 而今天学习的提示框是 通过视图控制器进行弹出,这就意味着,我们 ...