LeetCode 500 Keyboard Row 解题报告
题目要求
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.
题目分析及思路
给定一组字符串,要求只包含26个字母,可重复。要求返回的字符串符合以下条件:字符串中的每个字母只能出现在美国键盘上的同一行。可以将键盘上的三行字母用三个集合分别保存,并遍历每个字符串,将字符串小写并存入集合。若是已知三个集合中的一个的子集,即为所求字符串。
python代码
class Solution:
def findWords(self, words: 'List[str]') -> 'List[str]':
row1 = {'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'}
row2 = {'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'}
row3 = {'z', 'x', 'c', 'v', 'b', 'n', 'm'}
res = []
for s in words:
w = s.lower()
w = set(w)
if row1 & w == w or row2 & w == w or row3 & w == w:
res.append(s)
return res
LeetCode 500 Keyboard Row 解题报告的更多相关文章
- 【LeetCode】500. Keyboard Row 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力解 字典 + set 日期 题目地址:https ...
- 46. leetcode 500. Keyboard Row
500. Keyboard Row Given a List of words, return the words that can be typed using letters of alphabe ...
- Leetcode#500. Keyboard Row(键盘行)
题目描述 给定一个单词列表,只返回可以使用在键盘同一行的字母打印出来的单词.键盘如下图所示. 示例1: 输入: ["Hello", "Alaska", &quo ...
- LeetCode 500. Keyboard Row (键盘行)
Given a List of words, return the words that can be typed using letters of alphabet on only one row' ...
- [LeetCode] 500. Keyboard Row 键盘行
Given a List of words, return the words that can be typed using letters of alphabet on only one row' ...
- LeetCode: 500 Keyboard Row (easy)
题目: Given a List of words, return the words that can be typed using letters of alphabet on only one ...
- Week4 - 500.Keyboard Row & 557.Reverse Words in a String III
500.Keyboard Row & 557.Reverse Words in a String III 500.Keyboard Row Given a List of words, ret ...
- 【LeetCode】120. Triangle 解题报告(Python)
[LeetCode]120. Triangle 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址htt ...
- LeetCode 1 Two Sum 解题报告
LeetCode 1 Two Sum 解题报告 偶然间听见leetcode这个平台,这里面题量也不是很多200多题,打算平时有空在研究生期间就刷完,跟跟多的练习算法的人进行交流思想,一定的ACM算法积 ...
随机推荐
- 《软件测试自动化之道》读书笔记 之 底层的Web UI 测试
<软件测试自动化之道>读书笔记 之 底层的Web UI 测试 2014-09-28 测试自动化程序的任务待测程序测试程序 启动IE并连接到这个实例 如何判断待测web程序完全加载到浏览 ...
- .so.x不是符号连接
去到这个目录下查看,会发现有多个.so.x文件.x是版本号的区别.将它们动态软连接在一起就可以了 参考这个博客
- django 返回 code 405
return HttpResponse('Invalid Method',status=405)
- Java知多少(70)面向字节流的应用
文件输入输出流 文件输入输出流 FileInputStream 和 FileOutputStream 负责完成对本地磁盘文件的顺序输入输出操作. [例 10-5]通过程序创建一个文件,从键盘输入字符, ...
- [echarts] 横纵数据散点图
需求:课程平均分(X)与课程通过率散点图 http://echarts.baidu.com/echarts2/doc/example/scatter1.html https://www.cnblogs ...
- 【转】WPF自定义控件与样式(5)-Calendar/DatePicker日期控件自定义样式及扩展
一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等. 本文主要内容: 日历控件Calendar自定义样式: 日期控件DatePicker自定 ...
- Oracle清理回收站的方法
原文链接:http://blog.itpub.net/18841027/viewspace-1057765/ purge DBA_RECYCLEBIN用于删除Oracle数据库回收站的所有数据,需要s ...
- iLBC
iLBC是一种专为包交换网络通信设计的编解码,优于目前流行的G.729.G.723.1,对丢包进行了特有处理,即使在丢包率 相当高的网络环境下,仍可获得非常清晰的语音效果.
- Spring 3 Java Based Configuration with @Value
Springsource has released the Javaconfig Framework as a core component of Spring 3.0. There is a tre ...
- "佛祖保佑 永无bug" 注释模板设置详解(仅供娱乐)
1.注释模板效果图 今天在网上看到一段有趣的注释,佛祖保佑 永无bug, 效果如下图所示: 代码如下所示: /** * _ooOoo_ * o8888888o * 88" . " ...