题目描述

判断题目给出的字符串是不是回文,仅考虑字符串中的字母字符和数字字符,并且忽略大小写
例如:"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;
    }

};

leetcode26:valid-palindrome的更多相关文章

  1. [LeetCode] Valid Palindrome 验证回文字符串

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  2. 【leetcode】Valid Palindrome

    题目简述: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...

  3. Leetcode Valid Palindrome

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  4. [LintCode] Valid Palindrome 验证回文字符串

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  5. [LeetCode]题解(python):125 Valid Palindrome

    题目来源 https://leetcode.com/problems/valid-palindrome/ Given a string, determine if it is a palindrome ...

  6. 25. Valid Palindrome

    Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric char ...

  7. [Leetcode][JAVA] Valid Palindrome

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  8. Valid Palindrome [LeetCode]

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  9. 【LeetCode OJ】Valid Palindrome

    Problem Link: http://oj.leetcode.com/problems/valid-palindrome/ The following two conditions would s ...

  10. 【题解】【字符串】【Leetcode】Valid Palindrome

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

随机推荐

  1. Docker入门手册

    20.Docker 20.1 Docker的起源 2010年,几个搞IT的年轻人,在美国旧金山成立了一家名叫"dotCloud"的公司,这家公司主要提供基于PaaS的云计算技术服务 ...

  2. Linux为STDOUT的关键字设置颜色

    echo "颜色测试aaa实测" | perl -pe 's/(aaa|实|测)/\e[1;31m$1\e[0m/g'

  3. .NET 云原生架构师训练营(模块一 架构师与云原生)--学习笔记

    目录 什么是软件架构 软件架构的基本思路 单体向分布式演进.云原生.技术中台 1.1 什么是软件架构 1.1.1 什么是架构? Software architecture = {Elements, F ...

  4. 透视HTTPS建造固若金汤的城堡

    为什么有 HTTPS?因为 HTTP 不安全! 现在的互联网已经不再是 "田园时代","黑暗森林" 已经到来.上网的记录会被轻易截获,网站是否真实也无法验证,黑 ...

  5. volatile型变量语义讲解一 :对所有线程的可见性

    volatile型变量语义讲解一 :对所有线程的可见性 一.volatile变量语义一的概念 当一个变量被定义成volatile之后,具备两个特性: 特性一:保证此变量对所有线程的可见性.这里的&qu ...

  6. ie 版本判断脚本

    // 获取IE版本 /** * @return {string} */ function IEVersion() { // 取得浏览器的userAgent字符串 var userAgent = nav ...

  7. 多测师讲解requests __中_高级讲师肖sir

    (1)生成报告 import unittest #导入单元测试框架 import requests #导入接口库 import time # #时间戳,导入time模块 from api.HTMLTe ...

  8. jmeter 相关

    Don't use GUI mode for load testing !, only for Test creation and Test debugging. For load testing, ...

  9. PHP 超级全局变量 $_GET

    https://www.php.cn/php/php-superglobals.html https://m.php.cn/code/11853.html

  10. go 结构体函数

    package main import "fmt" type Dog struct { Name string } func (d *Dog) speak() string { r ...