(leetcode) Keyboard Row
来源:互联网 发布:linux 查看硬盘使用率 编辑:程序博客网 时间:2024/06/06 02:07
Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below.
take your keyboard as an example
- You may use one character in the keyboard more than once.
- You may assume the input string will only contain letters of alphabet.
Input: ["Hello", "Alaska", "Dad", "Peace"]Output: ["Alaska", "Dad"]
意思是检查字符串 是不是由一行输出的,只限字母,包括大小写
思路是把小写换成大写,这样字母表Ascii值就连续了,用一个长度26哈希表的,储存26个字符
属于第一列的值001,第二列的值010,第三列值100,检查是否为同一列 只要把该字符串的每个哈希值相与,结果不为0则为同一列
vector<string> findWords(vector<string>& words) {string a[3]={
"ASDFGHJKL",
"QWERTYUIOP",
"ZXCVBNM"};
vector<int>bucket(26);
vector<string>result;
for(int i=0;i<3;i++)
{
for(char c:a[i])
bucket[toupper(c)-'A']=1<<i; //001 010 100
}
}
for(auto i: words)
{
int t=7;
for(char c:i)
{
t&=bucket[toupper(c)-'A'];
}
if(t)
result.push_back(i);
}
return result;
}
0 0
- Leetcode-500. Keyboard Row
- 【Leetcode】500. Keyboard Row
- leetcode-500-Keyboard Row
- 【LeetCode】500. Keyboard Row
- LeetCode 500. Keyboard Row
- leetcode 500 keyboard row
- LeetCode 500. Keyboard Row
- Leetcode-Algorithms Keyboard Row
- [LeetCode]Keyboard Row - Python
- LeetCode:Keyboard Row
- leetcode 500. Keyboard Row
- Leetcode #500 Keyboard Row
- LeetCode 500 Keyboard Row
- [LeetCode]500. Keyboard Row
- LeetCode | 500. Keyboard Row
- [LeetCode]500. Keyboard Row
- LeetCode 500. Keyboard Row
- 【LeetCode】500. Keyboard Row
- 关于开机出现“安装程序正在为首次使用计算机做准备”的解决方案及微软OOBE与SYSPREP的实用技巧
- UART遇到两个与 stty 相关问题
- 单链表自动生成函数
- Geode多节点集群实验
- ios 使用自带的UIViewController实现qq加号下拉菜单的功能
- (leetcode) Keyboard Row
- Python安装Anaconda出现Error opening file for writing错误
- 程序员技术怀旧_晒晒那些过去的经典
- ReactiveCocoa学习篇——【下】
- poj 2355 DP 单调队列优化
- 一次涉及到物化视图的DB2 Insert性能问题的诊断
- Andorid即时获取电池信息(转载)
- java RSA/DSA/ECDSA实现数字签名
- 微信小程序开发总结