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.

    Note:
    Have you consider that the string might be empty? This is a good question to ask during an interview.

    For the purpose of this problem, we define empty string as valid palindrome.

    Solution:

    class Solution {
    public:
        bool isPalindrome(string s) {
            if(s.size() == 0) return true;
            int end = s.size() -1;
            int start = 0;
            while(start < end){
                while(start < end &&!isAlphanum(s[start])) start++;
                while(start < end &&!isAlphanum(s[end])) end--;
                if((s[start] != s[end])){
                    return false;
                }
                start++;
                end--;
            }
            return true;
        }
        
        bool isAlphanum(char &a){
            if(a <= '9' && a >= '0') return true;
            if(a <= 'z' && a >= 'a') return true;
            if(a <= 'Z' && a >= 'A'){
                a += 32;
                return true;
            }
            return false;
        }
    };
  • 相关阅读:
    Mycat之按照时间进行分片
    Mysql binlog解析器
    字体属性和文本属性总结
    css选择器
    CSS的三种引入方式
    CSS样式语法
    应用程序与数据库结合使用的三种方式
    存储过程
    子查询
    多表查询
  • 原文地址:https://www.cnblogs.com/yeek/p/3644731.html
Copyright © 2011-2022 走看看