题目要求

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. 【Linux】Linux基本命令扫盲

    [VI使用] 1.在命令行模式     :在vi编辑器中将光标放在函数上, 定位到每行的开头,不进入输入模式,$ 定位到每行的末尾     :[n]dd 剪贴n行,p粘贴     : dG 删除光标后 ...

  2. java中的数据加密1 消息摘要

    消息摘要(Message Digest) 又称为数字摘要(Digital Digest).它是一个唯一对应一个消息或文本的固定长度的值,它由一个单向Hash加密函数对消息进行作用而产生.如果消息在途中 ...

  3. ODbgScript 2.01帮助文档

    -------------------------------ODbgScript original pluginhttp://github.com/odbgscript--------------- ...

  4. Java SpringBoot中使用sqljdbc4注意事项 java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver

    因项目需要,需要在Java项目中访问 MSSQLServer 数据库,本地开发的时候,没有问题,可以正常链接数据库,通过Jenkins部署到服务器上时候,报数据库驱动未找到. java.lang.Cl ...

  5. Python 函数 (关键字参数)

    关键字参数 可变参数允许你传入0个或者任意个参数,这些可变参数在函数调用时会自动组装成一个tuple,而关键字参数允许你传入0个或者任意个含参数名的参数,这些参数在函数内部自动组装成为一个dict d ...

  6. [Tensorflow] Object Detection API - prepare your training data

    From: TensorFlow Object Detection API This chapter help you to train your own model to identify obje ...

  7. 转: jvm调优参数总结

    JVM里的GC(Garbage Collection)的算法有很多种,如标记清除收集器,压缩收集器,分代收集器等等,详见HotSpot VM GC 的种类 现在比较常用的是分代收集(generatio ...

  8. POJ 3249 Test for Job

    Test for Job Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 13457 Accepted: 3100 Descrip ...

  9. NLP入门资料

    <统计自然语言处理> 一些基础理论概念,涉及统计自然语言处理的基本概念.理论方法和新研究进展,内容包括形式语言与自动机及其在自然语言处理中的应用.语言模型.隐马尔可夫模型.语料库技术.汉语 ...

  10. day_10 py

    整理代码!!2018-7-24 20:53:49 直接复制了东西: 一些的demo 重点看蓝字部分! 就是一些简单的方法 基础的而已! 2018-4-22 15:50:26 继续py 还是py好玩感觉 ...