(C++)验证回文字符串

简介: (C++)验证回文字符串

愿所有美好如期而遇


题目

这道题比较简单,做一个没有感情的使用函数机器。

int tolower(int a); 将大写字母转换为小写字母。

void reverse (BidirectionalIterator first, BidirectionalIterator last);字符串逆置函数

以及字符串大小比较重载。

class Solution {
public:
    bool isPalindrome(string s) 
    {
        string newstr;
        for(int i=0; i<s.size(); i++)
        {
            if((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z'))
            {
                newstr += tolower(s[i]);
            }
            if(s[i] >= '0' && s[i] <= '9')
            {
                newstr += s[i];
            }
        }
        s = newstr;
        reverse(newstr.begin(),newstr.end());
        return s == newstr;
    }
};


目录
打赏
0
0
0
0
6
分享
相关文章
|
10月前
|
C++
验证回文串(C++)
验证回文串(C++)
35 0
第四十九练 请以递归方式实现判断一个字符串是否为回文字符串的
第四十九练 请以递归方式实现判断一个字符串是否为回文字符串的
58 0
|
10月前
|
java字符串练习题7、验证回文串
java字符串练习题7、验证回文串
128 0
|
10月前
|
括号序列:使用C++检查括号有效性
括号序列:使用C++检查括号有效性
193 0
|
10月前
leetcode-125:验证回文串
leetcode-125:验证回文串
69 0
|
10月前
|
算法编程(六):验证回文串
算法编程(六):验证回文串
68 0
🎖️typeScrpt中如何从验证字符串?
模板文字类型本质上是一种字符串类型。通过定义字符串必须匹配的模式,这些类型提供了一种验证和推断数据的方式。它们是大约三年前在 TypeScript 4.1 中引入的。根据最初的 GitHub PR,以下示例演示了 TypeScript 利用模板文字类型获得的多功能特性。
149 0
LeetCode 125. 验证回文串
LeetCode 125. 验证回文串
119 0