https://leetcode.com/problems/keyboard-row/
| 9 | * https://leetcode.com/problems/keyboard-row/ |
| 10 | */ |
| 11 | public 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected