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.

    #include<iostream>
    #include<string.h>
    using namespace std;
    bool isPalindrome(string s) 
    {
        string temp;
        if(s.length() == 0 || s.length() == 1)
            return 1;
            for(int i = 0;i<s.length();i++)
            {
                if(s[i]>='a' && s[i]<='z')
                {
                    temp += s[i];
                }
                else if(s[i] >= 'A' && s[i] <= 'Z')
                {
                    temp += (char)((int)s[i]+32);
                }
                else if(s[i]>='0' && s[i]<='9')
                {
                    temp += s[i];
                }
            }
            int low = 0;
            int high = temp.length()-1;
            bool result = true;
            if(temp.length()==0 || temp.length()==1)
                return 1;
            while(low < high)
            {
                if(temp[low] != temp[high])
                {
                    result = false;
                    return result;
                }
                else 
                {
                    low ++;
                    high --;
                }
            }
            return result;
    }


    int main()
    {
        //string s = "a.";
        cout << isPalindrome(s) << endl;
        system("pause");
        
        return 0;

    } 

  • 相关阅读:
    iOS 自带系统语音识别
    对iOS10新增Api的详细探究
    iOS 技术前瞻
    iOS 之 byte NSString NSData类型转换
    iOS 文本属性
    基本力
    xamarin mac 基础知识 之 界面
    xamarin mac 之 基础知识
    xamarin mac 之 资料
    I方法 thinkphp
  • 原文地址:https://www.cnblogs.com/xiawen/p/3291968.html
Copyright © 2011-2022 走看看