LeetCode Keyboard Row
来源:互联网 发布:php购物网站 编辑:程序博客网 时间:2024/06/05 17: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.
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.
import reclass Solution(object): def __init__(self): self.table1 = set('qwertyuiop') self.table2 = set('asdfghjkl') self.table3 = set('zxcvbnm') def findWords(self, words): """ :type words: list[str] :rtype: list[str] """ res = [] for i in words: ilower = set(i.lower()) if ilower.issubset(self.table1): res.append(i) elif ilower.issubset(self.table2): res.append(i) elif ilower.issubset(self.table3): res.append(i) return resclass Solution2(object): def findWords(self, words): return filter(re.compile('(?i)([qwertyuiop]*|[asdfghjkl]*|[zxcvbnm]*)$').match, words)class Solution3(object): def findWords(self, words): return [word for word in words if any(set(word.lower()) <= set(row) for row in [set('qwertyuiop'), set('asdfghjkl'), set('zxcvbnm')])]if __name__ == '__main__': print Solution3().findWords(["Hello", "Alaska", "Dad", "Peace"])
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-Algorithms Keyboard Row
- [LeetCode]Keyboard Row - Python
- LeetCode: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
- html学习01
- Educational Codeforces Round 12 C. Simple Strings 贪心
- ffmpeg 之 时间戳
- Appium+Python移动端自动化案例一个
- 实用故障例子
- LeetCode Keyboard Row
- python 配置文件(json文件)
- DBCP1.3连接泄露问题
- 【java开发部署】利用svn及ocaml及unison进行javaweb网站部署
- 2017.3.20 MATLAB(一)数据类型
- 如何创建一个Mavlink Message(一)
- MFC中CArray<CString,CString>m_FileItem是什么意思
- Mysql SELECT语句之limit参数
- Android 调用系统相机拍照(适配7.0)、从图库选择图片;从数据库读取联系人信息、相册图片