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. 快速排序的c++实现 和 python 实现

    最近在学python,其中有个要求实现快速排序的练习,就顺便复习了c++的快速排序实现. 快速排序的基本思想是,通过一轮的排序将序列分割成独立的两部分,其中一部分序列的关键字(这里主要用值来表示)均比 ...

  2. 小白用advanced installer建安装包

    写这篇文章的目的是由于肯定有人跟我一样非常小白,对安装包的构建又好奇.而我自己呢也要mark一下下,so--- 一.VS安装项目 首先关于安装包的构建,实用VS自带建安装项目的方式.网上有个中文工具叫 ...

  3. plsql类型

    --plsql基本数据类型1.标量类型1.1数字型--BINARY_INTEGER 来存储有符号整数.它的范围是-2**31至2**31.跟PLS_INTEGER一样,BINARY_INTEGER所需 ...

  4. Python+selenium之读取配置文件内容

    Python+selenium之读取配置文件内容 Python支持很多配置文件的读写,此例子中介绍一种配置文件的读取数据,叫ini文件,python中有一个类ConfigParser支持读ini文件. ...

  5. iOS开发之CocoaAsyncSocket学习

    本文转载至 http://blog.csdn.net/l_ch_g/article/details/17050757 AsyncSocket AsyncSocket类是支持TCP的AsyncUdpSo ...

  6. iOS-如何导出P12文件

    1.第一次用博客园,排版有点问题. 2.第一步点击进入Launchped 3.第二步点击钥匙串访问 4.第三步 找到登录下的Distribution 然后右键选择导出 5.第四步 选择下面的个人信息交 ...

  7. AndroidManifest.xml文件详解(activity)(二)

    android:configChanges 这个属性列出了那些需要Activity进行自我处理的配置变化.当在运行时配置变化发生的时候,默认情况下,这个Activity会被关掉并重启,但是用这个属性声 ...

  8. jeesite学习笔记(一) 项目框架

    JeeSite是基于多个优秀的开源项目,高度整合封装而成的高效,高性能,强安全性的开源Java EE快速开发平台. 在github上,对jeesite平台有详细的介绍,这里稍作整理,给出项目的内置功能 ...

  9. 将list集合,元素随机打乱

    for循环+随机数 实现相同位置的元素交换 public <T> void shuffle(List<T> list) { int size = list.size(); Ra ...

  10. k8s更新Pod镜像

    实际使用k8s中,如果使用RC启动pod可以直接使用滚动更新进行pod版本的升级,但是我们使用的情况是在pod里面启动有状态的mysql服务,没有和RC进行关联,这样更新的时候只能通过 更新pod的配 ...