题目要求

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:

  1. You may use one character in the keyboard more than once.
  2. 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 解题报告的更多相关文章

  1. 【LeetCode】500. Keyboard Row 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力解 字典 + set 日期 题目地址:https ...

  2. 46. leetcode 500. Keyboard Row

    500. Keyboard Row Given a List of words, return the words that can be typed using letters of alphabe ...

  3. Leetcode#500. Keyboard Row(键盘行)

    题目描述 给定一个单词列表,只返回可以使用在键盘同一行的字母打印出来的单词.键盘如下图所示. 示例1: 输入: ["Hello", "Alaska", &quo ...

  4. LeetCode 500. Keyboard Row (键盘行)

    Given a List of words, return the words that can be typed using letters of alphabet on only one row' ...

  5. [LeetCode] 500. Keyboard Row 键盘行

    Given a List of words, return the words that can be typed using letters of alphabet on only one row' ...

  6. LeetCode: 500 Keyboard Row (easy)

    题目: Given a List of words, return the words that can be typed using letters of alphabet on only one ...

  7. 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 ...

  8. 【LeetCode】120. Triangle 解题报告(Python)

    [LeetCode]120. Triangle 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址htt ...

  9. LeetCode 1 Two Sum 解题报告

    LeetCode 1 Two Sum 解题报告 偶然间听见leetcode这个平台,这里面题量也不是很多200多题,打算平时有空在研究生期间就刷完,跟跟多的练习算法的人进行交流思想,一定的ACM算法积 ...

随机推荐

  1. python开发-与其他语言的比较

    1.关于函数 1)不需要指定返回类型,不需要指定是否有返回值,每个函数都有返回值,没有的话,就返回None 2)参数也可以不指定类型,可以有默认参数,但是必须放到最后,调用的时候指定参数的值,和顺序无 ...

  2. 怎么关闭win10和win8快速启动

    电源选项-- 选择电源按钮的功能--- 更改当前不可用的设置-- 快速启动勾去掉

  3. mac 下 使用 java运行 class 文件 总是提示 “错误: 找不到或无法加载主类”的解决方法

    发现问题 切换到mac平台后,突然想写点程序运行在mac下,想到mac自带java,会方便好多.不过在这过程中遇到了麻烦: 总是提示 “错误: 找不到或无法加载主类” 工程结构 查了好久,终于找到原型 ...

  4. Swing中支持自动换行的WrapLayout

    http://www.cnblogs.com/TLightSky/p/3482454.html ———————————————————————————————————————————————————— ...

  5. 学习Mysql过程中拓展的其他技术栈:Docker入门介绍

    一.Docker的介绍和安装 1. Docker是什么 百度百科的介绍: Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linu ...

  6. Nginx配置详细

    ######Nginx配置文件nginx.conf中文详解##### #定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_ ...

  7. eclipse里将java工程改web工程

    转自:http://blog.csdn.net/heirenheiren/article/details/8488245 把一个普通的eclipse项目转成web项目 1.  编辑工程的.projec ...

  8. yum 快速安装centos7 mysql5.7

    CentOS7 yum方式安装MySQL5.7   在CentOS中默认安装有MariaDB,这个是MySQL的分支,但为了需要,还是要在系统中安装MySQL,而且安装完成之后可以直接覆盖掉Maria ...

  9. [hadoop] hadoop 运行 wordcount

    讲准备好的文本文件放到hdfs中 执行 hadoop 安装包中的例子 [root@hadoop01 mapreduce]# hadoop jar hadoop-mapreduce-examples-2 ...

  10. Navicat -- Oracle -- 错误锦集

    ORA:connection to server failed,probable Oracle Net admin error 解决的方案是: oci.dll的版本不对  从 http://www.o ...