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

 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. Cap&#39;n Proto, FlatBuffers, and SBE

    转自:utm_source=tuicool">http://kentonv.github.io/capnproto/news/2014-06-17-capnproto-flatbuff ...

  2. JavaBean属性

    一个JavaBean对象的属性应该是可访问的.这个属性可以是任意合法的Java数据类型,包括自定义Java类. 一个JavaBean对象的属性可以是可读写,或只读,或只写.JavaBean对象的属性通 ...

  3. 将Mac上的***代理共享给其他设备

    Windows版***带有Share over LAN功能,可以让一些不方便安装***客户端的设备一同“鸡犬升天”,如未越狱的iOS设备.但是 OS X 就没有这么幸运了,这时候你需要Privoxy助 ...

  4. json responseJson

    private void doResoponseJson(HttpServletResponse resp,String jsonString){ Trace.logError(Trace.COMPO ...

  5. SET ANSI_NULLS ON 在T-SQL中是什么意思

    from:https://www.cnblogs.com/kekong/p/6731321.html Transact-SQL 支持在与空值进行比较时,允许比较运算符返回 TRUE 或 FALSE. ...

  6. Python 基础爬虫架构

    基础爬虫框架主要包括五大模块,分别为爬虫调度器.url管理器.HTML下载器.HTML解析器.数据存储器. 1:爬虫调度器主要负责统筹其他四个模块的协调工作 2: URL管理器负责管理URL连接,维护 ...

  7. Java的版本历史与特性

    一个比较流行的问题是,“Java下一个版本会有什么特性呢?” .这是否是个好问题却有待商榷.在下面的内容里,我总结了至今为止的Java主要发行版中各自引入的新特性,这样做的目的是为了突出各个新特性是在 ...

  8. CodeIgniter框架——CI组件间信息流走向

    组件间信息流的走向图: 实线表示直接函数调用. 这些信息流可以从控制器到视图,也可以从控制器到类库或模型.(模型也能调用视图,但理论上这样做不合适.)相反方向就不能调用,如:视图不能调用控制器.然而, ...

  9. UESTC 482 Charitable Exchange(优先队列+bfs)

    Charitable Exchange Time Limit: 4000/2000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Othe ...

  10. UVA Dividing coins

    题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...