美文网首页
2019-11-25

2019-11-25

作者: 莹小武 | 来源:发表于2019-11-25 08:50 被阅读0次

bool isSubsequence(char * s, char * t){

    int subIndex[100] = {-1};

    for (int j = 0; j < 100; j++) {

        subIndex[j] = -1;

    }

    int sIndex = 0;

    int tIndex = 0;

    while (s[sIndex] != '\0') {

        tIndex = 0;

        while (t[tIndex] != '\0') {

            if (t[tIndex] == s[sIndex]) {

                subIndex[sIndex] = tIndex;

                break;

            }

            tIndex++;

        }

        sIndex++;

    }

    if ((sIndex == 1) && (subIndex[0] == -1)) {

        return false;

    }

    for (int i = 0; i < sIndex - 1; i++) {

        if (subIndex[i] >= subIndex[i + 1]) {

            return false;

        }

    }

    return true;

}

相关文章

网友评论

      本文标题:2019-11-25

      本文链接:https://www.haomeiwen.com/subject/zbcdwctx.html