c easy solution, but isn't 0ms


  • 0
    P
    int array[] = {2,1,1,2,3,2,2,2,3,2,2,2,1,1,3,3,3,3,2,3,3,1,3,1,3,1};
    char *rest[20000];
    int is_one_line(char *arg) {
        int pos = array[tolower(*arg) - 'a'];
        arg++;
        while(*arg != NULL) {
            if(pos != array[tolower(*arg) - 'a']) return false;
            arg++;
        }
        return true;
    }
    
    char** findWords(char** words, int wordsSize, int* returnSize) {
        char **res = rest;
        int ret = 0, index = 0;
        while(index < wordsSize) {
            if (is_one_line(words[index])) res[ret++] = words[index];
            index++;
        }
        
        *returnSize = ret;
        return res;
    }
    

Log in to reply
 

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