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

Method findWords

LeetCode/String/500. Keyboard Row/kaki5507.java:2–31  ·  view source on GitHub ↗
(String[] words)

Source from the content-addressed store, hash-verified

1class Solution {
2 public String[] findWords(String[] words) {
3
4 String[] line = {"^[QWERTYUIOP]*$","^[ASDFGHJKL]*$","^[ZXCVBNM]*$"};
5
6 ArrayList<String> arr = new ArrayList<String>();
7
8 for(int i = 0; i<words.length; i++) {
9
10 if(words[i].indexOf(line[0].charAt(0)) != 0) {
11 if(words[i].toUpperCase().matches(line[0]) == true) {
12 arr.add(words[i]);
13 }
14 }
15 if(words[i].indexOf(line[1].charAt(0)) != 0) {
16 if(words[i].toUpperCase().matches(line[1]) == true) {
17 arr.add(words[i]);
18 }
19 }
20 if(words[i].indexOf(line[2].charAt(0)) != 0) {
21 if(words[i].toUpperCase().matches(line[2]) == true) {
22 arr.add(words[i]);
23 }
24 }
25 }
26 String[] reArr = new String[arr.size()];
27 for(int i=0; i<arr.size(); i++) {
28 reArr[i] = arr.get(i).toString();
29 }
30 return reArr;
31 }
32}
33/*
34 String 배열로 리턴해줘야 합니다.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected