代码长了些,但还是比较简单的

 public class Solution {
public String[] findWords(String[] words) {
List<String> ansList = new ArrayList<String>();
Map<Character, Integer> charMap = new HashMap<Character, Integer>();
charMap.put('q', 1);charMap.put('w', 1);charMap.put('e', 1);charMap.put('r', 1);charMap.put('t', 1);
charMap.put('y', 1);charMap.put('u', 1);charMap.put('i', 1);charMap.put('o', 1);charMap.put('p', 1);
charMap.put('a', 2);charMap.put('s', 2);charMap.put('d', 2);charMap.put('f', 2);charMap.put('g', 2);
charMap.put('h', 2);charMap.put('j', 2);charMap.put('k', 2);charMap.put('l', 2);charMap.put('z', 3);
charMap.put('x', 3);charMap.put('c', 3);charMap.put('v', 3);charMap.put('b', 3);charMap.put('n', 3);
charMap.put('m', 3);
for(int i = 0; i < words.length; i++) {
boolean isSame = true;
Character c = new Character(words[i].charAt(0));
int pos = charMap.get(Character.toLowerCase(c));
for (int j = 1; j < words[i].length(); j++) {
c = new Character(words[i].charAt(j));
if (pos != charMap.get(Character.toLowerCase(c))) {
isSame = false;
break;
}
}
if (isSame == true)
ansList.add(words[i]);
}
String[] ans = new String[ansList.size()];
for (int i = 0; i < ansList.size(); i++) {
ans[i] = ansList.get(i);
}
return ans;
}
}

LeetCode: Keyboard Row的更多相关文章

  1. LeetCode——Keyboard Row

    LeetCode--Keyboard Row Question Given a List of words, return the words that can be typed using lett ...

  2. [LeetCode] Keyboard Row 键盘行

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

  3. 46. leetcode 500. Keyboard Row

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

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

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

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

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

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

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

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

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

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

  9. leetcode算法: Keyboard Row

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

随机推荐

  1. 创建Spring Boot项目的几种方式总结

    一.我们可以使用Spring Initializr来创建SpringBoot项目. Spring Initializr从本质上来说就是一个Web应用程序,它能为你生成Spring Boot项目结构.虽 ...

  2. plsql programming 09 数字

    number 类型, 十进制数据类型(平台无关的) pls_integer 和 binary_integer 这两种数据类型和你底层硬件表示整数的方法完全一致, 这两种类型的运算是利用硬件原生, 机器 ...

  3. Mysql闪回技术之 binlog2sql

    1.下载 https://github.com/danfengcao/binlog2sql http://rpmfind.net Search: python-pip pip 是一个Python包管理 ...

  4. SEO前端需要注意的地方

    1 合理的title ,description ,keyswords 搜索引擎对这三项的权重逐渐减小,title 强调重点即可,重要的关键字不要超过两次,而且要靠前. 2 不同的tilte要有所不同, ...

  5. [MongoDB]学习笔记--Linux 安装和运行MongoDB

    背景知识 MongoDB 是用C++写的, 开源的, NoSQL(Not Only SQL)文档数据库. 特点:high performance(高性能), high availability(高可靠 ...

  6. web容器 web服务器 servlet/jsp容器 之间的区别和关系是什么?

    web容器 web服务器 servlet/jsp容器 之间的区别和关系是什么? 这是我在网上找的一些资料:1. Web浏览器除了可以在本地硬盘上打开网页文档外,还可以使用http网络协议从网络上的We ...

  7. 查看java进程的所有信息

    查看java 进程下的所有信息 ll /proc/pid/fd ru:ll /proc/24047/fd

  8. 密钥管理服务KMS

    密钥管理服务 KMS - 腾讯云 https://cloud.tencent.com/product/kms

  9. javascript基础(整理自手册网)

    变量 person=null; //清空变量 carname="Volvo"; //赋值给未声明的变量, 它将会变成全局变量, 即使在函数内部 window.carnam; //所 ...

  10. iOS 多线程之 GCD 的基本使用

    什么是GCD 全称Grand Central Dispatch 中暑调度器 纯C语言 提供了很多强大的函数 GCD 的优势 GCD是苹果公司为多核的并行运算提出的解决方案 GCD会自动利用更多的CPU ...