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 };
  • 相关阅读:
    java位运算
    java笔试题(面试题)系列之一
    Java数据类型转换总结
    ++a和a++
    Java IO
    Java 并发
    Java位运算及补码存储
    Redis 5.0.0安装部署(伪集群版)
    Redis 安装(单机版)
    Dubbo源码分析系列之【服务暴露】
  • 原文地址:https://www.cnblogs.com/mengchunchen/p/7711292.html
Copyright © 2011-2022 走看看