题目要求

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. 【转】Django中使用POST方法获取POST数据

    1.获取POST中表单键值数据 如果要在django的POST方法中获取表单数据,则在客户端使用JavaScript发送POST数据前,定义post请求头中的请求数据类型: xmlhttp.setRe ...

  2. [echarts] 横纵数据散点图

    需求:课程平均分(X)与课程通过率散点图 http://echarts.baidu.com/echarts2/doc/example/scatter1.html https://www.cnblogs ...

  3. EventBus vs Otto vs Guava--自定义消息总线

    同步发表于http://avenwu.net/ioc/2015/01/29/custom_eventbus Fork on github https://github.com/avenwu/suppo ...

  4. oracle 11g 使用物化视图远程增量刷新数据

    ① 源数据库建立物化视图日志 drop MATERIALIZED VIEW LOG ON ORG_BASEINFO/ CREATE MATERIALIZED VIEW LOG ON ORG_BASEI ...

  5. swoole webSocket服务

    socket.php <?php //创建websocket服务器对象,监听0.0.0.0:9502端口 $ws = ); //监听WebSocket连接打开事件 (刚打开的时候会给客户端发送 ...

  6. Eclipse 中修改tomcat设置内存大小

    修改1: 在Eclipse中下面Servers双击Tomcat Server... 然后点击General InformAtion 下的Open launch configuration: 会弹出Ed ...

  7. 【Math】根据置信度、样本数相关推导过程

    时间长了会忘,备忘下. http://blog.csdn.net/liangzuojiayi/article/details/78044780 http://wiki.mbalib.com/wiki/ ...

  8. Nginx-配置https虚拟服务(访问http时自动跳转https)

    https口令文件和nginx配置文件位置关系: nginx配置文件内容如下: #user nobody; worker_processes 1; #设置工作进程数 pid logs/nginx.pi ...

  9. Android 信号处理面面观 之 信号定义、行为和来源

    总结: Android中: Sending signal. PID: XXX SIG: 3   ====>打印trace 原文:http://blog.csdn.net/rambo2188/ar ...

  10. vc写的dll被mingw的g++编译引用

    dll.cpp,用vc2017编译 #include <iostream>#include <windows.h> extern "C" __declspe ...