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 ...
随机推荐
- Mac版的idea部分按钮失效的解决方案
问题描述:调整了一下idea中jdk的路径,之后idea就无法打开新项目了,最好发现idea中的顶部菜单全部失效 解决过程: 1.把idea的jdk的路径调回去,无效 2.重启idea,无效 3.重启 ...
- sql insert and update
1 二者的区别 insert是插入一条新的数据,它会创建一条新的记录:update是更新一条已经有的数据,它不会创建新的记录. update需要where来指示更新那条记录,否则会更新所有的记录. 2
- C++ JSON解析库RapidJSON
https://github.com/Tencent/rapidjson jsontext.txt { "result" : [ { "face_id" : & ...
- js 时间戳精确值的问题
最近做一个多图上传的功能,通过name + 时间戳命名,结果发现时间戳竟然一样,一直以为是代码逻辑的问题,结果出错在时间戳的获取上了. 关于时间戳的获取方式: 1.Date.parse() var d ...
- HDU 1022 之 Train Problem I
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- POJ3080 Blue Jeans —— 暴力枚举 + KMP / strstr()
题目链接:https://vjudge.net/problem/POJ-3080 Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total ...
- poj 2253 Frogger 解题报告
题目链接:http://poj.org/problem?id=2253 题目意思:找出从Freddy's stone 到 Fiona's stone 最短路中的最长路. 很拗口是吧,举个例子.对 ...
- topcoder 的一些输入输出格式
自从上年的11月份参加过TC的比赛后,就再也没有参加了,因为它的输入输出格式比较难接受,还有它的页面字体比较小,看得我很辛苦...藉口藉口--懒而已!不过以后我会尽量去参加的,为了提高自己的编程能力. ...
- 并不对劲的bzoj4650:loj2083:uoj219:p1117:[NOI2016]优秀的拆分
题目大意 "优秀的拆分"指将一个字符串拆分成AABB的形式 十次询问,每次给出一个字符串S(\(|S|\leq3*10^4\)),求它的所有子串的优秀的拆分的方案数之和 题解 此题 ...
- writing-mode属性
writing-mode属性 最初只是ie中的属性,只有ie支持,现在在css3中谷歌,火狐也开始支持. 所以使用的时候就需要记住两套不同的语法,ie的私有属性和css3的规范属性 如果只需要兼容到i ...