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算法积 ...
随机推荐
- 【GMT43智能液晶模块】例程五:IWDG看门狗实验——复位ARM
实验原理: STM32内部包含独立看门狗,通过看门狗可以监控程序运行,程序运行 错误时,未在规定时间喂狗,自动复位ARM.本实验通过UI界面中按钮按下 停止喂狗,制造程序运行错误,从而产生复位. 示例 ...
- 【emWin】例程十三:字库放到外部存储器
介绍: 本例将字库文件放到SD卡中,通过读取SD卡中的字库文件在液晶上显示文字. 实验指导书及代码包下载: 链接:http://pan.baidu.com/s/1bo0yTLd 密码:i4sm ...
- 跨控制器跳转view——RedirectToRoute和RedirectToAction
已知控制器AccountController.cs和HomeController.cs,如果从页面Account/Login直接跳转到Home/Index,可以利用RedirectToRoute和Re ...
- pip离线安装软件包
1. 首先一台主机上安装所有python包,然后运行如下命令下载依赖包: pip freeze > requirements pip download -r requirements 当然可以在 ...
- 解决pymongo里操作IOSDate类型的问题
pymongo是Python对MongoDB的操作库.但是由于python没有IOSDate类型,所以对Mongo的时间类型是个很麻烦的操作.整理一个把python能识别的date类型转化为IOSDa ...
- cvCreateImage
CvCreateImage函数说明 cvCreateImage是openCV中的一个函数.OpenCV是Intel公司支持的开源计算机视觉库. cvCreateImage: 创建头并分配数据 ...
- Matlab如何循环读取文件
循环读取图片第一种方法①List =dir('*.jpg'); %如需其它图片格式支持,可以自己[重载dir()]函数,实现查找所有图片文件的功能,%如果图片是其它路径,可以用 ["路径&q ...
- SSH远程连接Linux配置
CentOS: 开启远程连接服务:service sshd start 添加到系统启动项:chkconfig sshd on 客户端工具:windows下连接工具putty ========= ...
- jq ajax post body raw传json
$.ajax( { url: '', 'data': JSON.stringify({ }), 'type': 'POST', 'processData': false, 'contentType': ...
- java-信息安全(十一)-非对称加密算法ECC
概述 信息安全基本概念: ECC算法(Elliptic curve cryptography,椭圆曲线密码学) ECC 椭圆加密算法(ECC)是一种公钥加密体制,最初由Koblitz和Miller两人 ...