题目要求

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. idea svn 不见的问题

    问题一: IntelliJ IDEA打开带SVN信息的项目不显示SVN信息,项目右键SVN以及图标还有Changes都不显示解决方法 在VCS菜单中有个开关,叫Enabled Version Cont ...

  2. <BEA-141281> <unable to get file lock, will retry ...>

    原文:http://gdutlzh.blog.163.com/blog/static/164746951201291903824812/ <BEA-141281> <unable t ...

  3. WebApi XML,Json格式自定义,IEnumerable<T>,ArrayOf

    global.ascx中application-start() GlobalConfiguration.Configuration.Formatters.XmlFormatter.UseXmlSeri ...

  4. java 注解默认值

    package com.zejian.annotationdemo; import java.lang.annotation.ElementType; import java.lang.annotat ...

  5. 程序-代写(qq:928900200)

    CS 310 Programming Assignment 4 Due April 27, 2014 5:00 P.M. About 15 years in the future... The Mar ...

  6. mysqldump导出数据时,某些表不导出,排除某些表,不导出某些表

    需求说明: 今天一同事问,在通过mysqldump导出数据库的时候,能不能把某些表不导出,或者叫做排除在外呢, 记得应该是可以实现,就搜索了下,通过mysqldump的--ignore-table参数 ...

  7. 【12月21日】A股滚动市盈率PE历史新低排名

    2010年01月01日 到 2018年12月21日 之间,滚动市盈率历史新低排名.上市三年以上的公司,2018年12月21日市盈率在300以下的公司. 1 - 厦门象屿(SH600057) - 历史新 ...

  8. 多密钥ssh-key生成与管理

    由于 git 大文件用 http 方式难以传输,必须使用 ssh-key,而 ssh-key 又生成了好多个.最近在各种折腾 ssh,公钥私钥上花费了很多时间,现将一些问题总结如下.系统为 Mac/L ...

  9. Android 集成ShareSDK分享QQ或空间成功后,回调却不执行的原因

    AndroidMainifest.xml中的如箭头所示的id一定要与assets下ShareSDK.xml中配置的QQ的AppId一定要相同. 如下图

  10. Docker集群管理portainer的使用

    1.Slave主机docker需要开启2375端口 ubuntu: sudo vim /etc/default/docker DOCKER_OPTS="-H=unix:///var/run/ ...