题目要求

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. 8个超实用的jQuery插件应用

    自jQuery诞生以来,jQuery社区都在不断地.自发地为jQuery创建许许多多功能不一的插件应用,很多jQuery插件非常实用,对我们的前端开发帮助相当大,不仅可以更完美的完成指定功能,而且节省 ...

  2. Vue中使用ECharts画散点图加均值线与阴影区域

    [本文出自天外归云的博客园] 需求 1. Vue中使用ECharts画散点图 2. 在图中加入加均值线 3. 在图中标注出阴影区域 实现 实现这个需求,要明确两点: 1. 知道如何在vue中使用ech ...

  3. 基于jQuery虾米音乐播放器样式代码

    分享一款基于jQuery虾米音乐播放器样式代码.这是一款基于jquery+html5实现的虾米音乐播放器源码下载.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div c ...

  4. 根据IP获取国家

    国外的还算比较权威的IP地址库,而且免费,每天调用次数不超过1000免费.超过另收费. public string Ip2Country(string ip) { try { string url = ...

  5. 【css】zSass - 用 sass 编写 css

    zSass 是自己整理的一个 sass 库,参考了 sassCore. 目录结构 variables.scss 默认值设置. reset.scss 重置浏览器样式.(参考:normalize) com ...

  6. JavaScript高级用法三之浏览器对象

    综述 本篇的主要内容来自慕课网,内置对象,主要内容如下 1 window对象 2 JavaScript 计时器 3 计时器setInterval() 4 取消计时器clearInterval() 5 ...

  7. CentOS最小化安装(一)

    一.配置网络 切记记得配置DNS,否则Ping不通 在目录中进行网络配置文件的查找:  /etc/sysconfig/network-scripts/ 1   1 /etc/sysconfig/net ...

  8. websphere 删除文件

    META-INF 文件夹下加入ibm-partialapp-delete.props即可 里面添加路径 如WEB-INF/xxx/xxx.xxx

  9. ruby的第一次使用

    今天看购买的小册,看到推荐使用的工具是ruby写的,提供了源码地址,但是不知道怎么使用 因此尝试使用了下ruby,并记录下来 1.安装 去ruby的官网,下载windows安装包 启动 Ruby 安装 ...

  10. Windowsclient SSH 远程连接Windowsserver(PowerShell Server)

    近期刚搞完SSH框架.又来研究研究SSH远程连接.为什么这么要弄这个呢?由于如今我如今开发主要在自己的笔记本(windows)上,然后写的后端都要部署到实验室的台式机(windows)上,这样一来,我 ...