valid Palindrome | Leetcode c++

来源:互联网 发布:.net 企业网站 源码 编辑:程序博客网 时间:2024/06/16 16:08

for this problem , you just need to use two pointers to judge whether it is a palindrome.

but what we should consider is to delete the " "  and such , . and other characters .

class Solution {public:    bool isPalindrome(string s) {    if(s.empty())      return true;    string t = "";    for(int i = 0;i< s.length();i++)    {      if((s[i] >= 'A'&& s[i]<='Z')||(s[i] >= 'a' && s[i] <= 'z' )|| (s[i] >='0'&&s[i] <='9'))        if(s[i] >= 'A' && s[i] <= 'Z')          t+= s[i]-'A'+'a';        else          t+=s[i];    };    for(int i = 0;i<t.length();i++)      if(t[i] != t[t.length()-1-i])        return false;    return true;    }};


0 0
原创粉丝点击