MCPcopy Create free account
hub / github.com/ROUTINE-STUDY/Algorithm / Sanghoo

Class Sanghoo

LeetCode/String/500. Keyboard Row/Sanghoo.java:11–35  ·  view source on GitHub ↗

https://leetcode.com/problems/keyboard-row/

Source from the content-addressed store, hash-verified

9 * https://leetcode.com/problems/keyboard-row/
10 */
11public class Sanghoo {
12
13 // 정규표현식을 활용하여 풀이하였습니다.
14 public String[] findWords(String[] words) {
15 String[] patterns = new String[]{"^[qwertyuiop]*$", "^[asdfghjkl]*$", "^[zxcvbnm]*$"};
16 List<String> list = new ArrayList<>(Arrays.asList(words));
17
18 for(int i=list.size()-1; i>=0; i--) {
19 String word = list.get(i).toLowerCase();
20 boolean isMatch = false;
21
22 for(String pattern : patterns) {
23 if(Pattern.matches(pattern, word)) {
24 isMatch = true;
25 break;
26 }
27 }
28 if(!isMatch) list.remove(i);
29 }
30
31 return list.toArray(new String[list.size()]);
32 }
33
34
35}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected