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 ...
随机推荐
- Html.Partial
老革命永远都在遇上各种似是而非的老问题. 这次,是这个Html.Partial,分部页. Html.Partial与Html.Action有啥区别呢?区别就是,Html.Partial只有一个视图,而 ...
- About "self"
Class method can't refer derectly to instance variables. Within the body of a class method, self re ...
- model.js
var Model = { inherited: function () {}, created: function () {}, prototype: { init: function (attrs ...
- 启动vmware中的虚拟机的时候,提示Failed to lock the file
http://www.vixual.net/blog/archives/842 VMware Server 當掉後重新啟動 Guest OS 時,出現 cannot open the disk '*. ...
- SKU多维属性状态判断算法
作者:周琪力,前端工程师,网络常用昵称「keelii」.在过去的4年里主要负责京东网站商品详情页的前端系统架构和开发,平时主要写 JavaScript 偶尔写点NodeJS,Python.琪力博客: ...
- 皮尔逊相关系数的java实现
相关系数的值介于–1与+1之间,即–1≤r≤+1.其性质如下:当r>0时,表示两变量正相关,r<0时,两变量为负相关.当|r|=1时,表示两变量为完全线性相关,即为函数关系.当r=0时,表 ...
- hdu 2112 HDU Today 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2112 题目意思:又是求最短路的,不过结合埋字符串来考查. 受之前1004 Let the Balloo ...
- html5--6-2 CSS语法
html5--6-2 CSS语法 实例 学习要点 掌握引入外部样式表方法 插入样式的三种方法 内联样式表(行内) 内部样式表(style中) 外部样式表 创建一个外部样式表 在head中使用link元 ...
- Ubuntu bitnami gitlab 安装
/************************************************************************************** * Ubuntu bit ...
- [Selenium] 操作浏览器 Cookies
WebDriver 提供了一系列 Cookies 的操作来获取.填写.删除 Cookies 的方法,节省了多次在登陆页面的查找元素并填写登录信息的时间. 1)获取 Cookies ,并保存到文件中以备 ...