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:
def isPalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
if s=='':
return True
import re
x = re.sub('\W','',s).lower()
if x=='':
return True
if(len(x)%2!=0):#数
for i in range(int(len(x)/2)+1):
if(x[i]!=x[len(x)-i-1]):
return False
else:
for i in range(int(len(x)/2)+1):
if(x[i]!=x[len(x)-i-1]):
return False
return True

125. Valid Palindrome(判断忽略标点的字符串是否回文,加个正则,与上一题解法一样)的更多相关文章

  1. 125. Valid Palindrome判断有效的有符号的回文串

    [抄题]: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...

  2. [leetcode]125. Valid Palindrome判断回文串

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

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

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

  4. LeetCode 125 Valid Palindrome(有效回文)(*)

    翻译 给定一个字符串.确定它是否是回文的,仅仅考虑当中的数字和字符并忽略其它. 比如. "A man, a plan, a canal: Panama" 是回文的. "r ...

  5. 125. Valid Palindrome【easy】

    125. Valid Palindrome[easy] Given a string, determine if it is a palindrome, considering only alphan ...

  6. java判断字符串是否回文

    java判断字符串是否回文 /** * java判断字符串是否回文<br><br> * 基本思想是利用字符串首尾对应位置相比较 * * @author InJavaWeTrus ...

  7. POJ 1159 Palindrome(字符串变回文:LCS)

    POJ 1159 Palindrome(字符串变回文:LCS) id=1159">http://poj.org/problem? id=1159 题意: 给你一个字符串, 问你做少须要 ...

  8. POJ 3280 Cheapest Palindrome(区间DP求改成回文串的最小花费)

    题目链接:http://poj.org/problem?id=3280 题目大意:给你一个字符串,你可以删除或者增加任意字符,对应有相应的花费,让你通过这些操作使得字符串变为回文串,求最小花费.解题思 ...

  9. UVA - 11584 划分字符串的回文串子串; 简单dp

    /** 链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34398 UVA - 11584 划分字符串的回文串子串: 简单 ...

随机推荐

  1. maven项目打ZIP包

    1.Maven插件配置: <!-- ZIP打包 --> <plugin> <artifactId>maven-assembly-plugin</artifac ...

  2. Memcached集群:Magent缓存代理使用

    小结: 先启动memcached 然后启动magent memcached -d -p 11211 -u memcached -m 64 -c 5120 memcached -d -p 11212 - ...

  3. tuning 03 Sizing the Share pool

    share pool : (组成) library cache: stores shared sql and pl/sql code (包含 statement text, parsed code, ...

  4. C++ 类的多态三(多态的原理--虚函数指针--子类虚函数指针初始化)

    //多态的原理--虚函数指针--子类虚函数指针初始化 #include<iostream> using namespace std; /* 多态的实现原理(有自己猜想部分) 基础知识: 类 ...

  5. 组件(Conponent)是图形用户界面最基本的部分

    组件(Conponent)是图形用户界面最基本的部分,也称为构件 ,是可以以图形化的方式显示在屏幕上,并能与用户进行交互的对象,例如一个按钮,一个标签等. 组件不能独立地显示出来,必须将其放在一定的容 ...

  6. (转)memcache、redis缓存

    memcache原理.内存模型: http://www.csdn.net/article/2016-03-16/2826609 redis原理: http://baike.baidu.com/link ...

  7. IPOL图像处理分析经典在线(文献+源码)

    网址: IPOL Journal · Image Processing On Line https://www.ipol.im/ 分类: 搜索: 下载文献和源码: NLM算法:IPOL Journal ...

  8. CAS SSO单点登录框架介绍

    1.了解单点登录  SSO 主要特点是: SSO 应用之间使用 Web 协议(如 HTTPS) ,并且只有一个登录入口. SSO 的体系中有下面三种角色: 1) User(多个) 2) Web 应用( ...

  9. [Go语言]从Docker源码学习Go——if语句和map结构

    if语句 继续看docker.go文件的main函数 if reexec.Init() { return } go语言的if不需要像其它语言那样必须加括号,而且,可以在判断以前,增加赋值语句 语法 I ...

  10. AngularJS 讲解,二 模块

    AngularJS允许我们使用angular.module()方法来声明模块,这个方法能够接受两个参数,第一个是模块的名称,第二个是依赖列表,也就是可以被注入到模块中的对象列表. angular.mo ...