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.

字符串为空时判断为回文,大小写不区分可确定相等,数字与字母不同。

 class Solution {
public:
bool isPalindrome(string s) {
int n=s.length();
if(n==) return true;
int i=,j=n-;
while(i<j){
if(!isCharacters(s[i])){
i++;
continue;
}
if(!isCharacters(s[j])){
j--;
continue;
} int left=,right=,leftsig=,rightsig=;
left=(s[i]>=''&&s[i]<='')?s[i]-'':((s[i]>='a'&&s[i]<='z')?s[i]-'a':s[i]-'A');
right=(s[j]>=''&&s[j]<='')?s[j]-'':((s[j]>='a'&&s[j]<='z')?s[j]-'a':s[j]-'A');
leftsig=(s[i]>=''&&s[i]<='')?:;
rightsig=(s[j]>=''&&s[j]<='')?:;
if(left!=right||leftsig!=rightsig)
return false;
i++;
j--;
}
return true;
}
bool isCharacters(char c){
if((c>='a'&&c<='z')||(c>='A'&&c<='Z')||(c>=''&&c<=''))
return true;
else
return false;
}
};

valid-palindrome——判断带符号数字字母的字符串是否为回文的更多相关文章

  1. 【Teradata SQL】从中文数字字母混合字符串中只提取数字regexp_substr

    目标:从中文数字字母的字符串中只提取数字 sel regexp_substr('mint choc中文11国1','\d+')

  2. 用递归方法判断字符串是否是回文(Recursion Palindrome Python)

    所谓回文字符串,就是一个字符串从左到右读和从右到左读是完全一样的.比如:"level" .“aaabbaaa”. "madam"."radar&quo ...

  3. [leetcode]131. Palindrome Partitioning字符串分割成回文子串

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  4. javascript判断给定字符串是否是回文

    //判断给定字符串是否是回文     function isPalindrome(word) {         var s = new Stack();         for (var i = 0 ...

  5. AC日记——判断字符串是否为回文 openjudge 1.7 33

    33:判断字符串是否为回文 总时间限制:  1000ms 内存限制:  65536kB 描述 输入一个字符串,输出该字符串是否回文.回文是指顺读和倒读都一样的字符串. 输入 输入为一行字符串(字符串中 ...

  6. C#进行回文检测,判断字符串是否是回文的代码

    下面代码内容是关于C#进行回文检测,判断字符串是否是回文的代码,应该是对各位朋友有些好处. Console.WriteLine("算法1:请输入一个字符串!");string st ...

  7. YTU 2802: 判断字符串是否为回文

    2802: 判断字符串是否为回文 时间限制: 1 Sec  内存限制: 128 MB 提交: 348  解决: 246 题目描述 编写程序,判断输入的一个字符串是否为回文.若是则输出"Yes ...

  8. Java - 判断字符串是否是回文

    首先,回文是指类似于“12345”,“abcdcba”的形式,即正念和反念都是一样的字符串 判断字符串是否是回文,这边介绍3种办法 将字符串翻转,判断翻转后的字符串和原字符串是否相等 public s ...

  9. C语言:判断字符串是否为回文,-函数fun将单向链表结点数据域为偶数的值累加起来。-用函数指针指向要调用的函数,并进行调用。

    //函数fun功能:用函数指针指向要调用的函数,并进行调用. #include <stdio.h> double f1(double x) { return x*x; } double f ...

随机推荐

  1. 鼠标在窗口中的坐标转换到 canvas 中的坐标

        鼠标在窗口中的坐标转换到 canvas 中的坐标 由于需要用到isPointInPath函数,所以必须得将鼠标在窗口中的坐标位置转换到canvas画布中的坐标,今天发现网上这种非常常见的写法其 ...

  2. 深度学习:Sigmoid函数与损失函数求导

    1.sigmoid函数 ​ sigmoid函数,也就是s型曲线函数,如下: 函数: 导数: ​ 上面是我们常见的形式,虽然知道这样的形式,也知道计算流程,不够感觉并不太直观,下面来分析一下. 1.1 ...

  3. 顺序表ans链性表

    #include<stdio.h>#include<malloc.h>#include<string.h>typedef int ElemType;typedef ...

  4. 给shell添加颜色

    编辑/etc/baserc 添加 TERM=xterm-color; export TERM alias ls='ls -G' alias ll='ls -lG' 给vim添加颜色 编辑/usr/sh ...

  5. 用JS去掉前后空格或中间空格大全

    1.  去掉字符串前后所有空格: -- js实现trim功能 //去除字符串前后所有空 function Trim(str) { return str.replace(/(^\s*)|(\s*$)/g ...

  6. 学习 JSP:第一步Eclipse+Tomcat+jre(配置环境)

    [下载软件](例子version:版本号) Eclipse从官网下载(version:4.7)http://www.eclipse.org/downloads/ jre从官网下载(version:1. ...

  7. 学习 WebService 第五步:在Local创建测试用WebService(WSDL)

    [准备] Eclipse+Tomcat7(Tomcat端口修改为不冲突的值) axis2 1.7.7 jar包(没有来这里下载:http://www.apache.org/dyn/closer.lua ...

  8. ADO:DataSet合并两张表( ds.Merge(ds1))

    原文发布时间为:2008-08-01 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...

  9. Linux 之 Memcached

    Memcached的安装使用 参考教程:[千峰教育] 环境:CentOS 6.8 一.简介: memcached作为高速运行的分布式缓存服务器,具有以下的特点. · 协议简单 · 基于libevent ...

  10. gzip: stdin: unexpected end of file tar: 归档文件中异常的 EOF

    gzip: stdin: unexpected end of file tar: 归档文件中异常的 EOF 问题描述: 使用tar命令解压文件时,报错: gzip: stdin: unexpected ...