Keyboard Row
来源:互联网 发布:淘宝图片版权保护 编辑:程序博客网 时间:2024/05/17 03:33
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.
American keyboard
Example 1:
Input: [“Hello”, “Alaska”, “Dad”, “Peace”]
Output: [“Alaska”, “Dad”]
class Solution {public: vector<string> findWords(vector<string>& words) { string book[3]={"qwertyuiop","asdfghjkl","zxcvbnm"}; vector<int> vt(26,0); for(int i = 0; i < 3; ++i){ for(auto& ch:book[i]){ vt[ch-'a']=i; } } vector<string> res; for(int i= 0;i<words.size();++i){ string temp = words[i]; char temp_ch = temp[0]; if(temp_ch>='A'&&temp_ch<='Z') temp_ch+=32; int flag = vt[temp_ch-'a']; bool valid = true; for(auto ch:temp){ if(ch>='A'&&ch<='Z') ch+=32; if(vt[ch-'a']!=flag){ valid = false; break; } } if(valid) res.push_back(temp); } return res; }};
0 0
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Leetcode-500. Keyboard Row
- 【Leetcode】500. Keyboard Row
- 500. Keyboard Row
- leetcode-500-Keyboard Row
- 500. Keyboard Row
- 【LeetCode】500. Keyboard Row
- 500. Keyboard Row
- oracle误删数据恢复方法
- linux下粘滞位引出的SUID和SGID
- 静默安装Oracle数据库10g篇
- 二维数组中的查找
- 华为网络笔试题
- Keyboard Row
- ADB Interface 驱动安装失效
- 向IPC进发
- NBUT1219 Time(打表,水题)
- Newtown Casino Hulk Slot Game Marvel Jackpot!(new town, newtoawn casino download, Newtown Casino, n)
- 通过管道和重定向实现linux管道命令(二)
- 有名管道(FIFO)实现无亲缘关系的客户服务器
- Android 下载 简单Dialog
- 验证管道只能用于有亲缘关系的进程通信