您好,欢迎来到伴沃教育。
搜索
您的当前位置:首页leetcode.125

leetcode.125

来源:伴沃教育
题目
/*
【分析】对照ascii表可知,数字字符范围48~57,大写字母范围65~90,小写字母范围97~122
*/
bool isPalindrome(char* s) {
    int low,high;
    low=0;high=strlen(s)-1;
    
    while(low<=high)
    {
        int x=s[low];int y=s[high];
        while(y<48||(y>57&&y<65)||(y>90&&y<97)||y>122)
        {
            if(high>0)
                y=s[--high];
            else
                return true;
        }
        while(x<48||(x>57&&x<65)||(x>90&&x<97)||x>122)
        {
            x=s[++low];
            
        }
        if(x>=65&&x<=90)
        {
            x=x+32;
        }
        if(y>=65&&y<=90)
        {
            y=y+32;
        }
        if(x!=y)
            return false;
        else 
            ++low;--high;
    }
    return true;
}

思路如程序

Copyright © 2019- bangwoyixia.com 版权所有 湘ICP备2023022004号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务