[LeetCode]500. Keyboard Row
来源:互联网 发布:splice软件安卓 编辑:程序博客网 时间:2024/05/21 07:15
题目大意:给出单词,找出都只在键盘同一行的字母组成的单词。
解题思路:简单模拟,遍历每个单词的字母,看是否都在同一行。
class Solution {public: vector<string> findWords(vector<string>& words) { int len = words.size(); bool f1,f2,f3; vector<string>res; unordered_set<char> r1 = {'q','Q','w','W','e','E','r','R','t','T','y','Y','u','U','i','I','o','O','p','P'}; unordered_set<char> r2 = { 'a','A','s','S','d','D','f','F','g','G','h','H','j','J','k','K','l','L'}; unordered_set<char> r3 = { 'z','Z','x','X','c','C','v','V','b','B','n','N','m','M'}; for(auto &word:words) { f1 = f2 = f3 = true; for(auto &i:word) { if(f1) { auto it = r1.find(i); if(it==r1.end()) f1 = false; } if(f2) { auto it = r2.find(i); if(it==r2.end()) f2 = false; } if(f3) { auto it = r3.find(i); if(it==r3.end()) f3 = false; } } if(f1 || f2 || f3) res.push_back(word); } return res; }};
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 | 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
- TCP与UDP
- 函数调用缺少参数列表;请使用“&Student::Printf”创建指向成员的指针 问题解析
- 功率放大器(PA)
- css nodeType
- EF批量删除执行
- [LeetCode]500. Keyboard Row
- maven 插件配置研究
- sklearn 文档翻译之 sklearn.cluster.KMeans
- 提升SQLite数据插入效率低、速度慢的方法
- 项目中产生的想法
- 设置适配器
- leetcode278. First Bad Version
- 作业1.RGB与YUV互转&AVI文件格式详解&WAV文件格式详解
- node后台文件下载浏览器兼容处理