Java O(n) solution - Concise and easy to understand


  • 0
    S
        public static String[] findWords(String[] words) {
            ArrayList<String> out = new ArrayList<String>();
            for(int i=0; i<words.length; i++){
                if(words[i].toUpperCase().matches("[QWERTYUIOP]+") ||
                   words[i].toUpperCase().matches("[ASDFGHJKL]+") ||
                   words[i].toUpperCase().matches("[ZXCVBNM]+")){
                        out.add(words[i]);
                }
            }
            return out.toArray(new String[out.size()]);
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.