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

 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. Vsphere笔记07 Vcenter 部署流程 2

    7.Vcenter 部署流程 2   Vcenter 安装需求   1.硬件要求 CPU:支持VT-X技术并开启内存:4G或4G 以上   2.系统要求 Windows 2008 R2 x64 Vsp ...

  2. Gold Balanced Lineup - poj 3274 (hash)

    这题,看到别人的解题报告做出来的,分析: 大概意思就是: 数组sum[i][j]表示从第1到第i头cow属性j的出现次数. 所以题目要求等价为: 求满足 sum[i][0]-sum[j][0]=sum ...

  3. Python 字典初始化dict()和{}

    参考:https://doughellmann.com/blog/2012/11/12/the-performance-impact-of-using-dict-instead-of-in-cpyth ...

  4. [前端开发] 未来趋势“无后端”的web应用开发模式

    最近看到前端趋势2013大会上的一篇文章,题目是<各位快看,不用后端>,觉得有点意思,恰好近期的一次讨论及半年前的一次开发实践也涉及到这种模式,简单谈谈我的想法. 不得不说,文章的题目确实 ...

  5. JavaScript 是脚本语言

    JavaScript 是一种轻量级的编程语言. JavaScript 是可插入 HTML 页面的编程代码. JavaScript 插入 HTML 页面后,可由所有的现代浏览器执行. JavaScrip ...

  6. redis的下载

    网址一:https://github.com/dmajkic/redis/downloads 网址二:http://windows.php.net/downloads/pecl/releases/re ...

  7. asp.net 页面延时五秒,跳转到另外的页面

    asp.net 页面延时五秒,跳转到另外的页面的实现代码. --前台 <%@ Page Language="C#" AutoEventWireup="true&qu ...

  8. Apache Nifi 开发

    Apache NiFi是由美国过国家安全局(NSA)贡献给Apache基金会的开源项目.其设计目标是自己主动化系统间的数据流.基于其工作流式的编程理念.NiFi很易于使用,强大.可靠及高可配置. 两个 ...

  9. 《PhotoShop CS6 》第一节 矢量与分辨率

    分辨率:不一定是方形,可以调整其比例. 色彩模型:色相Hue(圆周,冷暖相接),饱和度Saturation(半径),明度Brightness(轴,从黑到白).

  10. 学习 Unix 常用命令

    第一个是 man 命令,作用是:"Display system documentation",我是 manual 的缩写.通过这个命令,我们能了解接下来要学习的命令的文档. ls, ...