500. Keyboard Row
来源:互联网 发布:山东地税网络申报系统 编辑:程序博客网 时间:2024/06/13 10:53
题意:判断字符串数组中的每个字符串是否是在同一行上
思路:定义键盘字符数组对应的map,记录字符串的第一个字符所在的行,然后匹配下边字符,如果出现不同的val值,则不符合要求
class Solution {public: vector<string> findWords(vector<string>& words) { vector<string> res; if(words.size()==0)return res; int len=words.size(); string a[]={"QWERTYUIOP","ASDFGHJKL","ZXCVBNM"}; map<char,int> mp; for(int i=0;i<3;i++) for(int j=0;j<a[i].length();j++) { mp[a[i][j]]=i; } for(int i=0;i<len;i++) { char temp=words[i][0]>='a'? words[i][0]-32:words[i][0]; int flag=mp[temp]; bool flag1=true; for(int j=1;j<words[i].length();j++) { temp=words[i][j]>='a'? words[i][j]-32:words[i][j]; if(mp[temp]!=flag) { flag1=false; break; } } if(flag1) res.push_back(words[i]); } return res; }};
0 0
- Leetcode-500. Keyboard Row
- 【Leetcode】500. Keyboard Row
- 500. Keyboard Row
- 500. Keyboard Row
- 【LeetCode】500. Keyboard Row
- 500. Keyboard Row
- LeetCode 500. Keyboard Row
- 500. Keyboard Row
- 500. Keyboard Row
- LeetCode 500. Keyboard Row
- 500. Keyboard Row
- 500. Keyboard Row (E)
- 500. Keyboard Row
- 500. Keyboard Row
- leetcode 500. Keyboard Row
- 500. Keyboard Row
- [LeetCode]500. Keyboard Row
- 500. Keyboard Row
- 触发器
- 不懂知识点杂记
- Maven 环境变量配置
- MFC 利用checkbox 做成切换开关按钮
- MCC(移动国家码)和 MNC(移动网络码)
- 500. Keyboard Row
- Html5学习入门指引
- C/C++中extern关键字详解
- 【论文笔记】Fully Convolutional Networks for Semantic Segmentation
- listView 嵌套gridView android
- 使用Google官方API进行全球定位
- vi/vim查找替换方法
- 原型链图解
- WOFF2与icon字体化