zoukankan      html  css  js  c++  java
  • leetcode26:valid-palindrome

    题目描述

    判断题目给出的字符串是不是回文,仅考虑字符串中的字母字符和数字字符,并且忽略大小写
    例如:"A man, a plan, a canal: Panama"是回文
    "race a car"不是回文
    注意:
    你有没有考虑过字符串可能为空?这是面试时应该提出的一个好问题。
    针对这个问题,我们定义空字符串是回文


    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.

    示例1

    输入

    复制
    "A man, a plan, a canal: Panama"

    输出

    复制
    true
    
    示例2

    输入

    复制
    "race a car"

    输出

    class Solution {
    public:
        /**
         *
         * @param s string字符串
         * @return bool布尔型
         */

    bool isPalindrome(string s) {
            int i,j;
            for(i=0,j=s.length()-1;i<j;++i,--j){
                while(i<j && !isalnum(s[i])) ++i;
                while(i<j && !isalnum(s[j])) --j;
                if (i<j && tolower(s[i])!=tolower(s[j])) return false;
            }
            return true;
        }

    };

  • 相关阅读:
    Linux下的lds链接脚本详解
    STM32启动过程解读与跟踪验证
    STM32的启动过程分析
    STM32启动过程--启动文件--分析
    STM32之中断
    STM32F4XX启动文件分析
    Synergy CORTEX M 启动流程
    AT 指令和常见错误码
    Tomcat部署时war和war exploded区别
    C++虚函数表解析***
  • 原文地址:https://www.cnblogs.com/hrnn/p/13417015.html
Copyright © 2011-2022 走看看