llllmz

导航

125. 验证回文串c

bool judge(char c){
    if(c>='a'&& c<='z' || c>='A' && c<='Z' || c>='0' && c<='9' ) return true;
    return false;
}

bool isPalindrome(char* s) {
    int n=strlen(s);
    char* array=(char*)malloc(sizeof(char)*(n+1));
    int head=0,index=0;
    while(index<n){
        if(judge(s[index])){
            if(s[index]>='A' && s[index] <= 'Z') s[index]=s[index]-'A'+'a';
            array[head++]=s[index++];
        }else{
            index++;
        }
    }
    for(int i=0;i<head;i++) printf("%c",array[i]);
    if(head==0) return true;
    int tail=head-1;
    head=0;
    while(head<=tail){
        if(array[head]!=array[tail]) return false;
        head++;
        tail--;
    }
    return true;
}

 

posted on 2024-03-21 20:38  神奇的萝卜丝  阅读(2)  评论(0编辑  收藏  举报