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算法积 ...
随机推荐
- 【九天教您南方cass 9.1】 05 打印出图
同学们大家好,欢迎收看由老王测量上班记出品的cass9.1视频课程 我是本节课主讲老师九天. 我们讲课的教程附件也是共享的,请注意索取测量空间中. [点击索取cass教程]5元立得 (给客服说暗号:“ ...
- cbow与skip-gram
场景:上次回答word2vec相关的问题,回答的是先验概率和后验概率,没有回答到关键点. 词袋模型(Bag of Words, BOW)与词向量(Word Embedding)模型 词袋模型就是将句子 ...
- 使用Ajax异步上传图片的方法(html,javascript,php)
前两天项目中需要用到异步上传图片和显示上传进度的功能,于是找了很多外国的文章,翻山越岭地去遇上各种坑,这里写篇文章记录一下. HTML <form id="fileupload-for ...
- qualcomm wifi kernel beacon loss 日志记录
记录一下高通对于beacon loss的处理的日志.方便后面再来分析. 04:17:13.397139 [04:17:13.383909] [000000A81699E7EC] [VosMC] wla ...
- linux 如何快速的查找日志中你所要查找的信息
在工作中我总会通过日志来查找相关问题,但有时候日志太多有不知道又不知道日志什么时候打印的,这时我们可以通过一下方法来查找: 1.把目录跳到你日志文件存放的地方 2.grep 关键字 * 例如 ...
- 文件解压缩 tar zip
zip -e var-log-protected.zip /var/log/* Enter password: Verify password: updating: var/log/acpid (de ...
- [CNN] Understanding Convolution
From: http://blog.csdn.net/zouxy09/article/details/49080029 一个概念需经过反复的推敲以及时间的沉淀,之后才能真正理解 [OpenCV] Im ...
- [Full-stack] 异步即时通信 - Async
故事背景 socket.io, node.js, koa为首的一些通信框架和后端技术点. 之后有必要过一遍<NodeJS 设计模式>. 基础概念 一.短轮询.长轮询(comet).长连接( ...
- 【PHP】xampp配置多个监听端口和不同的网站目录(转)
转自:https://blog.csdn.net/cc1314_/article/details/75646344 windows下使用xampp配置多个监听端口和不同的网站目录 一:配置Apache ...
- python使用requests发送multipart/form-data请求数据
def client_post_mutipart_formdata_requests(request_url,requestdict): #功能说明:发送以多部分表单数据格式(它要求post的消息体分 ...