力扣-125题 验证回文串(C++)- 字符串+双指针

题目链接:https://leetcode-cn.com/problems/valid-palindrome/
题目如下:
在这里插入图片描述

class Solution {
    
    
public:
    bool isPalindrome(string s) {
    
    
        string str;
        for(auto ch:s){
    
    
            if(isalnum(ch)){
    
    
                str+=tolower(ch);
            }
        }
        
		//双指针
        int l=0,r=str.size()-1;
        while(l<r){
    
    
            if(str[l]!=str[r]) return false;
            l++;
            r--;
        }
        
        return true;
    }
};

おすすめ

転載: blog.csdn.net/qq_40467670/article/details/121238824