• 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;

    } 

  • 相关阅读:
    ubuntu LAMP的安装
    windows中安装liunx虚拟机
    jQuery Responsive OneByOne Slider Plugin
    轮播图收集
    移动端图片延迟加载插件
    图片幻灯插件
    小tip: base64:URL背景图片与web页面性能优化
    基于HTML5的可预览多图片Ajax上传
    字体平滑解决方案
    webstorm scss编译css配置
  • 原文地址:https://www.cnblogs.com/xiawen/p/3291968.html
Copyright © 2020-2023  润新知