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

    判断是不是回文串  只考虑字母和数字  忽略大小写和其他的

    isalpha 字母(包括大写、小写)

    islower(小写字母)

    isupper(大写字母)

    isalnum(字母大写小写+数字)

    isblank(space和 )

    isspace(space、 、 、 )

    C++(9ms):

     1 class Solution {
     2 public:
     3     bool isPalindrome(string s) {
     4         int i = 0 ;
     5         int j = s.size() - 1 ;
     6         while(i < j){
     7             if (!isalnum(s[i])) i++ ;
     8             else if (!isalnum(s[j])) j-- ;
     9             else if (toupper(s[i++]) != toupper(s[j--]))
    10                 return false ;    
    11         }
    12         return true ;
    13     }
    14 };
  • 相关阅读:
    xlrd doc
    安装Python package
    Python处理Excel(转载)
    OPENSSL简介
    sublime text2教程
    使用SQL 从表中取记录
    SQL基础
    shell脚本之grep的使用方法
    (转载)(收藏)OceanBase深度解析
    (转载)线程池的使用
  • 原文地址:https://www.cnblogs.com/mengchunchen/p/7711292.html
Copyright © 2011-2022 走看看