leetcode500. Keyboard Row
来源:互联网 发布:淘宝主图怎么做 编辑:程序博客网 时间:2024/05/29 03:35
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 like the image below.
American keyboard
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.
解法
正则匹配
public class Solution { public String[] findWords(String[] words) { if (words == null || words.length == 0) { return words; } List<String> list = new ArrayList<>(); String regex = "[qwertyuiop]*|[asdfghjkl]*|[zxcvbnm]*"; for (String str : words) { if (str.toLowerCase().matches(regex)) { list.add(str); } } String[] ret = new String[list.size()]; for (int i = 0; i < list.size(); i++) { ret[i] = list.get(i); } return ret; }}
阅读全文
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
- openTSDB安装,部署
- 接口和抽象类有什么区别?
- AngularJS Directive 隔离 Scope 数据交互
- faster-rcnn训练和测试自己的数据(VGG/ResNet)以及遇到的问题
- java-第二篇
- leetcode500. Keyboard Row
- CRC检验--循环冗余检验
- (5)JDBC的PreparedStatment对象使用
- Mybaties中的总结<一>
- PostgreSQL LIKE 查询效率提升实验
- Maven详解之聚合与继承
- 软件工程复习资料(四)
- MFC实现连连看二:地图的显示
- 多个线程共享变量的例子,线程为什么要Thread.sleep