【leetcode】 数组中的字符串匹配

 

char ** stringMatching(char ** words, int wordsSize, int* returnSize){
    char** arr = (char**)calloc(wordsSize,sizeof(char*));
    int n =0;
    for (int i=0; i<wordsSize; i++)
    {
        for (int j=0; j<wordsSize; j++)
        {
            if (i == j) continue;
            if (strstr(words[j],words[i])) 
            {
                arr[n++] = words[i];
                break;
            }
        }
    }
    *returnSize = n;
    return arr;
}

 

posted @ 2020-09-04 15:04  温暖了寂寞  阅读(183)  评论(0编辑  收藏  举报