JAVA 8ms Regex solution. Very short and easy to understand.

  • 0
    public String[] findWords(String[] words) {
      List<String> res = new ArrayList<String>();
      for(String str : words) {
        if(str.matches("[qwertyuiopQWERTYUIOP]*") || 
           str.matches("[asdfghjklASDFGHJKL]*") || str.matches("[zxcvbnmZXCVBNM]*"))
      return res.toArray(new String[res.size()]);

Log in to reply

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