inline bool check_abc(char c){
//printf("check : %c\n", c);
if((c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9')) return true;
return false;
}
inline bool check_123(char c){
if( (c>='0' && c<='9')) return true;
return false;
}
bool isPalindrome(char* s) {
int i=0, j=strlen(s)-1, tmp = abs('A' - 'a');
while(i<j) {
while(i<j && !check_abc(s[j]))
j--;
while(i<j && !check_abc(s[i]))
i++;
//printf("i=%d, j=%d \n", i, j);
if(s[i]-s[j] == 0 || (abs(s[i]-s[j]) == tmp && (!check_123(s[i]) && !check_123(s[j])))) {
} else{
return false;
}
i++;
j--;
}
return true;
}
leetcode-125-验证回文串-C语言
字符串回文检查
最新推荐文章于 2025-02-09 17:55:01 发布
本文介绍了一种使用C语言实现的字符串回文检查算法。通过定义内联函数check_abc和check_123来判断字符是否为字母或数字,再通过isPalindrome函数逐对比较字符串首尾字符,忽略非字母数字字符,最终确定字符串是否为回文。
1803

被折叠的 条评论
为什么被折叠?



