[leetcode: Python]500.Keyboard Row
来源:互联网 发布:怎么写好网络小说知乎 编辑:程序博客网 时间:2024/06/05 15:36
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"]
Note:
You may use one character in the keyboard more than once.
You may assume the input string will only contain letters of alphabet.
方法一:55ms
class Solution(object): def findWords(self, words): """ :type words: List[str] :rtype: List[str] """ wset = map(set,['qwertyuiop','asdfghjkl','zxcvbnm']) ans = [] for word in words: wordi = set(word.lower()) if any(wordi <= rset for rset in wset): ans.append(word) return ans
方法二:42ms
class Solution(object): def findWords(self, words): """ :type words: List[str] :rtype: List[str] """ keyboard = ["qwertyuiop", "asdfghjkl", "zxcvbnm"] out = [] for i in words: for line in keyboard: lword = i.lower() if set(lword).issubset(set(line)): out.append(i) return out
阅读全文
0 0
- [leetcode: Python]500.Keyboard Row
- [LeetCode]Keyboard Row - Python
- 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
- 简单的图片翻转实现方式
- 图像处理基础知识总结1
- 文章标题
- 最近的学习计划
- 转移 MySql 的数据目录
- [leetcode: Python]500.Keyboard Row
- Android N 添加系统服务Freg
- spark 2.1 the runJob process
- Android上的RN不能展示尺寸大的图,怎么办?
- 滑动窗口的方法解决一些String的查找问题
- Android 禁止状态栏下拉
- lintcode 在二叉查找树中插入节点
- 制作mac系统正式版U盘USB启动安装盘方法教程 (全新安装 Mac 系统)
- CentOS6.7 上面安装Docker 1.7.1