leetcode 125. 验证回文串 c++

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/glw0223/article/details/88848757

125. 验证回文串

分析

  • 两头往中间比较
class Solution {
public:
    bool isPalindrome(string s) {
        int j=0;
        //忽略大小写
        for(auto &c:s){
            if(c>='a'&&c<='z'||c>='0'&&c<='9')               
                s[j++]=c;
           else if(c>='A'&&c<='Z')
                s[j++]=c-'A'+'a';
        }
        //验证回文
        for(int i=0;i<j/2;i++)
            if(s[i]!=s[j-1-i])
                return false;
        return true; 
    }
};

猜你喜欢

转载自blog.csdn.net/glw0223/article/details/88848757
今日推荐