zoukankan      html  css  js  c++  java
  • Valid Palindrome

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

    For example,
    "A man, a plan, a canal: Panama" is a palindrome.
    "race a car" is not a palindrome.

    class Solution {
    public:
        bool isPalindrome(string s) {
            int sSize = s.size();
            int i=0,j=sSize-1;
            int diff = 'a'-'A';
            while(i<j){
                while((i<j) && !((s[i]>='a' && s[i]<='z') || (s[i]>='A' && s[i]<='Z') || (s[i]>='0' && s[i]<='9'))){i++;}
                while((i<j) && !((s[j]>='a' && s[j]<='z') || (s[j]>='A' && s[j]<='Z') || (s[j]>='0' && s[j]<='9'))){j--;}
                if(i>=j){
                    return true;
                }
                if(s[i]==s[j] || s[i]==s[j]+diff || s[j] == s[i]+diff){
                    i++;
                    j--;
                }else{
                    return false;
                }
            }
            return true;
        }
    };
  • 相关阅读:
    TeX中的引号
    竖式问题
    蛇形填数
    开灯问题
    排列
    分数化小数
    子序列的和
    cookie
    post请求
    get请求
  • 原文地址:https://www.cnblogs.com/zengzy/p/5003834.html
Copyright © 2011-2022 走看看