500. Keyboard Row
来源:互联网 发布:唯弋女装旗舰店淘宝 编辑:程序博客网 时间:2024/06/06 03:18
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 isSame(int pos0, int pos1){ if(pos0 <= 9 && pos1 <= 9) return true; else if(9 < pos0 && pos0 <= 18 && 9 < pos1 && pos1 <= 18) return true; else if(18 < pos0 && pos0 <= 25 && 18 < pos1 && pos1 <= 25) return true; else return false; } vector<string> findWords(vector<string>& words) { string mode = "qwertyuiopasdfghjklzxcvbnm"; int first = 9, second = 18, third = 25; vector<string> v; for(int i = 0; i < words.size(); ++i){ string str = words[i]; int j = 1, len = str.length(); for(; j < len; ++j){ int pos0 = mode.find(tolower(str[j - 1]), 0); int pos1 = mode.find(tolower(str[j]), 0); if(!isSame(pos0, pos1)) break; } if(j == len) v.push_back(str); } return v; }};
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
- CentOS 6.5安装jdk1.8
- PrintWriter与ServletOutputStream的区别
- linux c 线程间同步的三种方法
- Java设计模式之装饰模式
- MyEclipse详细优化配置,背景颜色,字体,加载模块
- 500. Keyboard Row
- c++中的string大小写转换方法
- 手机app端,token的详解
- linux入门:find指令
- Lucene 6.10 初级 创建索引库和利用索引库进行搜索!
- win7 64位安装redis 及Redis Desktop Manager使用
- 查询两个时间段是否有交集的情况
- SSH项目实战---图书销售及后台管理系统
- 我们为什么要配置环境变量