美文网首页
leetcode.125

leetcode.125

作者: 小气的王二狗 | 来源:发表于2018-10-16 19:59 被阅读9次
    题目
    /*
    【分析】对照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;
    }
    

    思路如程序

    相关文章

      网友评论

          本文标题:leetcode.125

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