首页 > 代码库 > LeetCode-500. Keyboard Row
LeetCode-500. Keyboard Row
Given a List of words, return the words that can be typed using letters of alphabet on only one row‘s of American keyboard
public class Solution { public String[] findWords(String[] words) { if (words == null) return new String[0]; String[] r = {"qwertyuiop", "asdfghjkl", "zxcvbnm"}; List<String> rets = new ArrayList<String>(); for (String ws : words) { String w = ws.toLowerCase(); char first = w.charAt(0); int in = 0; while (in < 3) { if (r[in].contains(first+"")) break; in ++; } boolean all = true; for (int i=1; i<w.length(); i++) { if (!r[in].contains(w.charAt(i)+"")) { all = false; break; } } if (all) { rets.add(ws); } } return rets.toArray(new String[0]); } }
LeetCode-500. Keyboard Row
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。