【LeetCode】500. Keyboard Row【E】【75】
来源:互联网 发布:jsp和php 编辑:程序博客网 时间:2024/06/04 19:03
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.
Subscribe to see which companies asked this question.
想法很简单 就是用集和运算 然后看每个word是不是一行的子集
最开始写的时候 太傻了 被注释掉了
class Solution(object): def findWords(self, words): #row1 = set(['Q','W','E','R','T','Y','U','I','O','P','q','w','e','r','t','y','u','i','o','p']) #row2 = set(['A','S','D','F','G','H','J','K','L','a','s','d','f','g','h','j','k','l']) #row3 = set(['Z','X','C','V','B','N','M','z','x','c','v','b','n','m']) row1 = set('qwertyuiop') row2 = set('asdfghjkl') row3 = set('zxcvbnm') res = [] for i in words: si = set(i.lower()) #if len(si - row1) == 0 or len(si - row2) == 0 or len(si - row3) == 0: if si.issubset(row1) or si.issubset(row2) or si.issubset(row3): res += i, return res """ :type words: List[str] :rtype: List[str] """
0 0
- 【LeetCode】500. Keyboard Row【E】【75】
- 500. Keyboard Row (E)
- 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
- 预处理器运算符
- 堆和栈的区别
- I2C知识点
- Combination Sum系列的三个题目39,40,216--重要(和78. Subsets ,90. Subsets II类似)
- 【Python爬虫4】并发并行下载
- 【LeetCode】500. Keyboard Row【E】【75】
- VGA标准消隐时间查询表
- activeform三级联动 [ 2.0 版本 ]
- Python学习之&输入输出(一)
- HASH 与MAP 的区别
- openGPS.cn - 如何防范被高精度IP定位采集数据
- 动态规划解决0/1背包问题
- 为RecylerView添加item点击事件
- Yii2.0 中 jQuery、CSS的引入 [ 2.0 版本 ]