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

 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. Android 之布局

    1.RelativeLayout相对布局 a).第一类:属性值为true或false android:layout_centerHrizontal 水平居中 android:layout_center ...

  2. hdu5673 Robot 卡特兰数+组合数学+线性筛逆元

    Robot Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  3. 第一百八十五节,jQuery,Ajax 表单插件

    jQuery,Ajax 表单插件 学习要点: 1.核心方法 2.option 参数 3.工具方法 传统的表单提交,需要多次跳转页面,极大的消耗资源也缺乏良好的用户体验.而这款 form.js 表单的 ...

  4. Hibernate一对多映射列表实例(使用xml文件)

    如果持久化类具有包含实体引用的列表(List)对象,则需要使用一对多关联来映射列表元素. 在这里,我们使用论坛应用场景,在论坛中一个问题有多个答案. 在这种情况下,一个问题可以有多个答案,每个答案可能 ...

  5. jQuery CSS 操作函数

    CSS 属性 描述 css() 设置或返回匹配元素的样式属性. height() 设置或返回匹配元素的高度. offset() 返回第一个匹配元素相对于文档的位置. offsetParent() 返回 ...

  6. Codeforces Round #404 (Div. 2) DE

    昨晚玩游戏竟然不小心错过了CF..我是有多浪啊. 今天总算趁着下课时间补了,感觉最后两题还是挺有意思的,写个题解. D: 题目大意: 给出一个括号序列,问有多少个子序列 是k个'(' + k个')' ...

  7. CentOS 6.5 Git源码安装

    首先清除系统自带git,使用如下命令 yum -y remove git 一.下载Git源码包 wget https://www.kernel.org/pub/software/scm/git/git ...

  8. 第二章----python基础

    概要:python是一种计算机编程语言,有自己的一套语法,编译器或者解释器负责把符合语法的程序代码翻译成CPU能识别的机器码,然后执行.python使用缩进来组织代码块,Python程序中大小写是敏感 ...

  9. Scanner类与Random类

    1.Scanner类 Scanner类的作用是获得输入,下面代码用于获得用户的键盘输入,实例如下: 常用方法: String next():将输入信息的下一个标记扫描为一个字符串 Int nextIn ...

  10. iOS-获取的NSDate date时间与实际相差8个小时解决方案

    本文转载至 http://blog.sina.com.cn/s/blog_51a995b70101iptl.html NSDate *date = [NSDate date]; NSTimeZone  ...