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. 那些让人睡不着觉的bug,你有没有遭遇过?

    我先讲一个小故事,以前在外企工作时的一个亲身经历. 当时我所在的team,负责手机上多媒体Library方面的开发.有一天,一个具有最高等级的bug被转到了我的手上.这个bug非常诡异,光是重现它就需 ...

  2. CI 跳转

    redirect('home/play/index');

  3. 左萧龙(LZ)个人博客

    网址(blog):http://www.cnblogs.com/zuoxiaolong/ 网站:http://www.zuoxiaolong.com/

  4. 【SVM】清晰明了的理论文章

    http://www.cnblogs.com/jerrylead/archive/2011/03/13/1982639.html 松弛变量和惩罚因子: http://blog.csdn.net/yan ...

  5. c++11小计

    [capture] (parameters) mutable -> return-type { statement } " (parameters)" 和 "-&g ...

  6. django用户认证系统——拓展 User 模型2

    Django 用户认证系统提供了一个内置的 User 对象,用于记录用户的用户名,密码等个人信息.对于 Django 内置的 User 模型, 仅包含以下一些主要的属性: username,即用户名 ...

  7. 在asp.net页面上得到Castle容器的实例

    在项目中使用Castle IOC容器,Asp.net程序中如何得到Castle容器内. 可以如下实现: 1.Gloabal实现接口IContainerAccessor public class Glo ...

  8. IIS部署ASP.NET MVC (4.0)网站出现的错误

    (1)无法读取配置节“system.web.extensions”,因为它缺少节声明 在IIS中,在基本设置中,将程序池选择为ASP.NET 4.0即OK! (2)由于 Web 服务器上的“ISAPI ...

  9. text-align:justify 使用参考

    对 text-align:justify 不大了解的,可以先看这里:从css text-align:justify 谈谈 text-align 文本对齐方式,讲的比较浅显易懂,本篇相对深入些,最好先看 ...

  10. sql---字段类型转换,sql获取当前时间

    一.字段类型转换 convert(要转换成的数据类型,字段名称)例如 convert(varchar(100),col_name)Convert(int,Order_no) 二.sql获取当前时间 s ...