题目描述

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

    Centos6.8 1.查看自己的内核 [1].uname [root@host79 ~]# uname -r 2.6.32-642.el6.x86_64 [2].查看CentOS版本信息 CentO ...

  2. C#数据结构-双向链表

    链表的概念以及链表与数组的差异不做过多的叙述,相信大家都耳熟能详,这里以c#语言实现简单的双向链表,作为备用,记录下~ public class Node<T> { private Nod ...

  3. RHSA-2017:2907-重要: wpa_supplicant 安全更新

    [root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) 修复命令: 使用root账号登陆She ...

  4. web中的HTML CSS

    HTML  超文本标记语言      页面的结构  首行声明文档类型>根标记>头部标记/主体标记      标记         div 布局 切割 分割 划分区域         spa ...

  5. docker下安装kafka和kafka-manager

    1.下载镜像 这里使用了wurstmeister/kafka和wurstmeister/zookeeper这两个版本的镜像 docker pull wurstmeister/zookeeper doc ...

  6. centos8平台php7.4.2安装phpredis实现对redis的访问

    一,下载phpredis 1,官方下载地址: https://github.com/phpredis/phpredis/releases 2,wget下载 [root@yjweb source]# w ...

  7. arcgis activeX 安全提示消除办法

    点击任何的一个ArcToolBox 工具,光标落在参数输入框时,会提示 "在此页面上的ActiveX控件和本页上的其他部分的交互可能不安全.你想允许这种交互操作吗? " 消除办法 ...

  8. RocketMQ扫盲篇

    本篇博客主要参考: <浅入浅出>-RocketMQ 敖丙 APACHE-RocketMQ Gitee RocketMQ官方文档 RocketMQ 实战与进阶 GitChat 又是好久没有写 ...

  9. Jmeter入门(3)- Jmeter录制脚本

    一. 录制web端 1. Badboy的介绍和安装 1.1 使用第三方工具Badboy来录制. 免费的web自动化测试工具 一个浏览器模拟工具 主要进行脚本的录制和回访,和对录制脚本进行调试,可以将脚 ...

  10. mock.js 学习

    安装 npm install mockjs 使用 // 引入 import Mock from 'mockjs' Mock.setup({ timeout: '200 - 400' }) const ...