My Java Solution


  • 0
    H

    public String[] findWords(String[] words){
    if(words.length == 0)
    return words;
    String[] ret = new String[words.length];
    int n = 0;
    String[] w = {"qwertyuiop", "asdfghjkl", "zxcvbnm"};
    for(int i = 0; i < words.length; i++){
    char[] array = words[i].toLowerCase().toCharArray();
    int j;
    if(w[0].indexOf(array[0]) > -1)
    j = 0;
    else if(w[1].indexOf(array[0]) > -1)
    j = 1;
    else
    j = 2;

            int k = 1;
            for(; k < array.length; k++){
                if(w[j].indexOf(array[k]) == -1)
                    break;
            }
            if(k == array.length) {
                ret[n] = words[i];
                n++;
            }
        }
        return Arrays.copyOf(ret, n);
    

    }


Log in to reply
 

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