leetcode 500. Keyboard Row(easy)
来源:互联网 发布:怎样在淘宝买微博小号 编辑:程序博客网 时间:2024/06/05 18:28
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.
Example 1:
Input: ["Hello", "Alaska", "Dad", "Peace"]Output: ["Alaska", "Dad"]
Note:
- You may use one character in the keyboard more than once.
- You may assume the input string will only contain letters of alphabet.
class Solution {public: bool isOneRow(string s,map<char,int> &temp) { int len = s.length(); int flag = 0; for(int i = 0;i<len;i++) { if(i == 0) flag = temp[toupper(s[i])]; else { int m = temp[toupper(s[i])]; if(flag != m) return false; } } return true; } vector<string> findWords(vector<string>& words) { map<char,int> temp; temp['A'] = 2; temp['S'] = 2; temp['D'] = 2; temp['F'] = 2; temp['G'] = 2; temp['H'] = 2; temp['J'] = 2; temp['K'] = 2; temp['L'] = 2; temp['Q'] = 1; temp['W'] = 1; temp['E'] = 1; temp['R'] = 1; temp['T'] = 1; temp['Y'] = 1; temp['U'] = 1; temp['I'] = 1; temp['O'] = 1; temp['P'] = 1; temp['Z'] = 3; temp['X'] = 3; temp['C'] = 3; temp['V'] = 3; temp['B'] = 3; temp['N'] = 3; temp['M'] = 3; vector<string> result; vector<string>::iterator iter = words.begin(); for(;iter != words.end();++iter) { if(isOneRow(*iter,temp)) result.push_back(*iter); } return result; }};
0 0
- LeetCode :【Easy】500. Keyboard Row
- leetcode 500. Keyboard Row(easy)
- LeetCode 500. Keyboard Row (Easy)
- 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
- [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
- Java数据结构(三)——集合总结及集合的线程安全
- 底部导航BottomNavigationView+ViewPager+Fragment
- python——OrderedDict 、importlib
- ant+jmeter快速搭建
- 存储过程实例3:批量提交
- leetcode 500. Keyboard Row(easy)
- 文件输入输出方式设置值
- 计算机网络之OSI七层模型与TCP/IP四层模型
- 第三十六讲项目一M$pszi$y是嘛意思?
- GUI图形初步实现
- java 重定向问题 主要用来解决图片的上传问题
- 细说一个汉字等于几个字符,以及汉字,字符,字节,位之间的关系
- iOS应用跳转对应应用评价的链接
- Java 项目的导入(import)和导出(export)