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.

    Solution:

    class Solution {
    public:
        bool isPalindrome(string s) {
            string ss = "";
            for(int i = 0;i < s.length();i++)
            {
              if(s[i] >= 'A' && s[i] <= 'Z')
                ss += s[i] - 'A' + 'a';
              else if(s[i] >= 'a' && s[i] <= 'z')
                ss += s[i];
                else if(s[i] >= '0' && s[i] <= '9')
                    ss += s[i];
            }
    
            if(ss.length() < 2)
              return true;
            else
            {
              for(int i = 0;i < ss.length() / 2;i++)
              {
                if(ss[i] != ss[ss.length() - 1 - i])
                  return false;
              }
              return true;
            }
        }
    
    };
  • 相关阅读:
    P1909 买铅笔
    树形结构
    图片
    cookie
    JSON
    操作数组
    竖线分割|
    订单提交中... 后前面三点动画
    w'w
    解决扫码枪输入input时受中文输入法的影响
  • 原文地址:https://www.cnblogs.com/changchengxiao/p/3600322.html
Copyright © 2011-2022 走看看