zoukankan      html  css  js  c++  java
  • [leetcode]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.

    明天就是五一小长假了,突然有点失落呀,每次放假都有点囧~~ 这是一个非常非常无聊的题,符合现在的心情,所以就写写了。。。

    class Solution {
    public:
        bool isPalindrome(string s) {
            // Start typing your C/C++ solution below
            // DO NOT write int main() function
            int p=0, q=s.size()-1;
            
            while(p<q){            
                if(!((s[p] >= 'a' && s[p] <= 'z') || (s[p] >= 'A' && s[p] <= 'Z') ||(s[p] - '0' >= 0 && s[p] -'0'<=9))) {
                    p++;
                    continue;
                }
                if(!((s[q] >= 'a' && s[q] <= 'z') || (s[q] >= 'A' && s[q] <= 'Z') ||(s[q] - '0' >= 0 && s[q] -'0'<=9))) {
                    q--;
                    continue;
                }
                
                if(s[p]!=s[q] && s[p]-s[q] != 'A'-'a' && s[p]-s[q] != 'a'-'A') 
                    return false;
                p++;
                q--;           
            }
            return true;
            
        }
    };


  • 相关阅读:
    CCF NOI1006 捡石头
    POJ NOI MATH-7648 蓄水池水管问题
    CCF NOI1005 存款收益
    CCF NOI1004 填充矩形
    CCF NOI1003 猜数游戏
    CCF NOI1002 三角形
    Project Euler Problem 26 Reciprocal cycles
    HDU1799 循环多少次?
    CCF NOI1001 温度转换
    POJ NOI MATH-7647 余数相同问题
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3049832.html
Copyright © 2011-2022 走看看