[LeetCode]Keyboard Row - Python
来源:互联网 发布:js分享微信朋友圈插件 编辑:程序博客网 时间:2024/06/05 03:44
输入一个字符串list,如[“Hello”, “Alaska”, “Dad”, “Peace”],对于list中的每一个字符串,如果这个字符串中的字母的集合小于等于键盘上的任意一行字母的集合,就输出这个字符串。在此例子中,输出[“Alaska”, “Dad”]。
class Solution(object):def findWords(self, words): """ :type words: List[str] :rtype: List[str] """ res = [] for row in [set('qwertyuiop'),set('asdfghjkl'),set('zxcvbnm')]: for word in words: w = word.lower() if set(w)<=row: res.append(word) return res
set为python的集合类型,为一个无序的不重复的元素集,如
代码就很好理解,对于输入的list中的每一个字符串,如果这个字符串的元素集小于等于键盘上任意一行的元素集,就表示这个字符串可以仅有其一行组成。
0 0
- [LeetCode]Keyboard Row - Python
- [leetcode: Python]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-Algorithms Keyboard Row
- 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
- 进程间通信——消息队列
- opencv学习(三十二)之图像边缘检测Soble_Laplace_Canny
- I.MX6Q GPIO驱动的编写
- Android 缓存机制(一)
- bzoj3529: [Sdoi2014]数表
- [LeetCode]Keyboard Row - Python
- 发的好地方根据您发的
- 面向对象思想
- identifier of an instance of com.you.hibernate.model.TStudentInfo was altered from 6 to 7
- 进程间通信——共享内存
- 开放才能进步!Angular和Wijmo一起走过的日子
- socket自定义数据格式转化二进制
- 二分查找
- HDU1023_Train Problem II_卡特兰数