leetcode500: Keyboard Row
来源:互联网 发布:网络电视机那个牌子好 编辑:程序博客网 时间:2024/05/16 09:17
Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below.
Example 1:
Input: ["Hello", "Alaska", "Dad", "Peace"]Output: ["Alaska", "Dad"]
Note:
- You may use one character in the keyboard more than once.
- You may assume the input string will only contain letters of alphabet.
注意:这个程序说明如何返回一个String[]
public String[] findWords(String[] words) {String q1 = "QWERTYUIOP";String a1 = "ASDFGHJKL";String z1 = "ZXCVBNM";ArrayList q = new ArrayList();ArrayList a = new ArrayList();ArrayList z = new ArrayList();List<String> re = new LinkedList<>();for (int i = 0; i < q1.length(); i++)q.add(q1.charAt(i));for (int i = 0; i < a1.length(); i++)a.add(a1.charAt(i));for (int i = 0; i < z1.length(); i++)z.add(z1.charAt(i));for (int i = 0; i < words.length; i++) {char[] candidate = words[i].toUpperCase().toCharArray();boolean flag1 = true;boolean flag2 = true;boolean flag3 = true;for (int j = 0; j < candidate.length; j++) {if (q.contains(candidate[j]))flag1 = false;else if (a.contains(candidate[j]))flag2 = false;else if (z.contains(candidate[j]))flag3 = false;elsebreak;}if (((flag1 == false) && (flag2 == true) && (flag3 == true))|| ((flag1 == true) && (flag2 == false) && (flag3 == true))|| ((flag1 == true) && (flag2 == true) && (flag3 == false)))re.add(words[i]);}return re.toArray(new String[0]);}
0 0
- leetcode500: Keyboard Row
- leetcode500 Keyboard Row Java
- Leetcode500. Keyboard Row
- leetcode500. Keyboard Row
- LeetCode500. Keyboard Row
- Leetcode500. Keyboard Row
- python--leetcode500. Keyboard Row
- 14.leetCode500:keyboard row
- LeetCode500. Keyboard Row我的C++解法
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Linux进程通信(一)——pipe管道
- C++ operator关键字(重载操作符)
- javascript的位置:<head>或者<body>
- java单链表reverse
- Unity说明文档翻译-Getting Started
- leetcode500: Keyboard Row
- Hibernate框架使用中出现could not instantiate RegionFactory 异常的解决方法
- 线程同步-CountDownLatch
- 监督学习-k近邻算法模板
- windows下编译wireshark错误
- MySql学习(七) —— 查询性能优化 深入理解MySql如何执行查询
- HTML5属性扩展总结
- 程序员道路
- JSON和XML的利弊