Valid Palindrome

来源:互联网 发布:手机画衣柜软件 编辑:程序博客网 时间:2024/06/01 21:06

回文数的另一种形式。比int的回文稍难,但思路还是比较清晰的,判断好大小写、空格、义字符就行。

如下:

bool isAlpha(char *s){    bool reuslt = false;    if ((*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <= 'Z') || (*s >= '0' && *s <= '9')) {        reuslt = true;    }    return reuslt;}bool isPalindrome(char* s) {    if (!s)        return true;    bool result = true;    char *low = s, *high = s + strlen(s) - 1;    while(*low) {        if (!isAlpha(low)) {            low++;            continue;        }        if (!isAlpha(high)) {            high--;            continue;        }        if (*low - *high != 32 && *low - *high != -32 && *low - *high != 0) {            result = false;            break;        }        low++, high--;    }        return result;}


0 0
原创粉丝点击