Leetcode #500 Keyboard Row
来源:互联网 发布:网络漫画培训 编辑:程序博客网 时间:2024/05/01 20:34
Description
Given a List of words, return the words that can be typed using letters of alphabet on only one row’s of American keyboard.
Note
- You may use one character in the keyboard more than once.
- You may assume the input string will only contain letters of alphabet.
Example
Input: [“Hello”, “Alaska”, “Dad”, “Peace”]
Output: [“Alaska”, “Dad”]
Explain
单词各字母都在键盘上同一行则输出该单词
Code
class Solution(object): def findWords(self, words): """ :type words: List[str] :rtype: List[str] """ top = ['q','Q','w','W','e','E','r','R','t','T','y','Y','u','U','i','I','o','O','p','P'] mid = ['a','A','s','S','d','D','f','F','g','G','h','H','j','J','k','K','l','L'] buttom = ['z','Z','x','X','c','C','v','V','b','B','n','N','m','M'] res = [] for item in words: a = b = c = 0 for i in item: if i in top: a = 1 if i in mid: b = 1 if i in buttom: c = 1 if a + b + c == 1: res.append(item) return res
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 500 Keyboard Row
- Leetcode 500 Keyboard Row
- LeetCode-500-Keyboard Row
- LeetCode.500 Keyboard Row
- leetcode 500 Keyboard Row C++
- leetcode 500 Keyboard Row Add to List
- Leetcode-500. Keyboard Row
- 【Leetcode】500. Keyboard Row
- 【LeetCode】500. Keyboard Row
- LeetCode 500. Keyboard Row
- LeetCode 500. Keyboard Row
- 【福利】JetBrains 全家桶2017激活码,2016版本可用,有效期至2018
- maven格式
- C++之引用的注意点(1)
- 技术解读第二章
- 使用JDK开发WebService-服务器端建立
- Leetcode #500 Keyboard Row
- android NetworkInfo类
- ASP.NET MVC5 实现分页查询
- 前端切图技能总结
- bzoj1922 [Sdoi2010]大陆争霸 有限制最短路
- HashMap源码解析
- 自定义view-使用xml控制界面的呈现
- 2.26
- 80. Remove Duplicates from Sorted Array II