• 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  check(char test, char & c)
        {
           if(test >= 'a' && test <= 'z')
           {
            c = test;
            return true;
           }else if(test >= 'A' && test <= 'Z'){
         
            c = test - 'A' + 'a';
            return true;
           }else if (test >= '0' && test <= '9'){
         
              c = test;
              return true;
           }
           return false;
        }
        bool isPalindrome(string s) {
            // Start typing your C/C++ solution below
            // DO NOT write int main() function
            int j = s.length();
            if(j-- == 0) return true;
            int i = 0; char head,tail;
            while(i<j){
                while(i<j){
                    if(check(s[i],head)) break;
                    i++;
                }
                if(i>=j) return true;
                
                while(i<j){
                    if(check(s[j], tail)) break;
                    j--;
                }
                if(i>=j) return true;
                if(head != tail ) return false;
                i++;j--;
            }
            return true ;
        }
    };
  • 相关阅读:
    查看java代码,命令,ctrl+r
    JVM调优
    springboot线程池
    jpa
    复制java对象,jpa,save
    springboot添加切面
    gunicorn 实现 gevent 多线程
    经典算法
    python-生僻字转拼音
    HTML介绍
  • 原文地址:https://www.cnblogs.com/graph/p/3251420.html
Copyright © 2020-2023  润新知