125. Valid Palindrome(判断忽略标点的字符串是否回文,加个正则,与上一题解法一样)
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(判断忽略标点的字符串是否回文,加个正则,与上一题解法一样)的更多相关文章
- 125. Valid Palindrome判断有效的有符号的回文串
[抄题]: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...
- [leetcode]125. Valid Palindrome判断回文串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- [LeetCode] 125. Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- LeetCode 125 Valid Palindrome(有效回文)(*)
翻译 给定一个字符串.确定它是否是回文的,仅仅考虑当中的数字和字符并忽略其它. 比如. "A man, a plan, a canal: Panama" 是回文的. "r ...
- 125. Valid Palindrome【easy】
125. Valid Palindrome[easy] Given a string, determine if it is a palindrome, considering only alphan ...
- java判断字符串是否回文
java判断字符串是否回文 /** * java判断字符串是否回文<br><br> * 基本思想是利用字符串首尾对应位置相比较 * * @author InJavaWeTrus ...
- POJ 1159 Palindrome(字符串变回文:LCS)
POJ 1159 Palindrome(字符串变回文:LCS) id=1159">http://poj.org/problem? id=1159 题意: 给你一个字符串, 问你做少须要 ...
- POJ 3280 Cheapest Palindrome(区间DP求改成回文串的最小花费)
题目链接:http://poj.org/problem?id=3280 题目大意:给你一个字符串,你可以删除或者增加任意字符,对应有相应的花费,让你通过这些操作使得字符串变为回文串,求最小花费.解题思 ...
- UVA - 11584 划分字符串的回文串子串; 简单dp
/** 链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34398 UVA - 11584 划分字符串的回文串子串: 简单 ...
随机推荐
- 【Mac + GitHub】之在另一台Mac电脑上下载GitHub的SSH链接报错
当输入git命令github项目时报错: ⇒ git clone git@github.com:/TX-Class.git Cloning into 'TX-Class'... Warning: Pe ...
- iOS -转载-字符串是否为空判断方法
- (BOOL)blankString{ if (![self isKindOfClass:[NSString class]] ){ return YES; } if ([self isEqual:[ ...
- [越狱开发] theOpenDev配置与搭建碰到的问题
CodeSign error: code signing is required for product type 'Dynamic Library' in SDK 'iOS 6.1' 如何解决?
- 一个Demo展示Storyboard的强大
本文转载至http://www.cocoachina.com/ios/20150330/11440.html 今天我通过完成一个长按cell删除的Demo,向你们展示熟练运用storyboard和Au ...
- Spinner --- 功能和用法
第一种方法: 使用Spinner时需要配置选项的资源文件,资源文件为一个string类型的数组 在res下的values文件夹下新建一个xml文件 内容为: <?xml version=&quo ...
- 【BZOJ4385】[POI2015]Wilcze doły 单调栈+双指针法
[BZOJ4385][POI2015]Wilcze doły Description 给定一个长度为n的序列,你有一次机会选中一段连续的长度不超过d的区间,将里面所有数字全部修改为0.请找到最长的一段 ...
- CodeForces 668B Little Artem and Dance
B. Little Artem and Dance time limit per test 2 second memory limit per test 256 megabytes input sta ...
- MySQL中的注释(有三种)
MysQL支持三种注释: .#... (推荐这种,具有通性) ."-- ..." (注意--后面有一个空格) ./*...*/
- 史上最全Vim快捷键键位图 -- 入门到进阶
文章欢迎转载,但转载时请保留本段文字,并置于文章的顶部 作者:卢钧轶(cenalulu) 本文原文地址:http://cenalulu.github.io/linux/all-vim-cheatshe ...
- Oracle数据库模型(OLAP/OLTP)
数据库模型 选择数据库模型: 联机事务处理OLTP(on-line transaction processing) OLTP是传统的关系数据库的主要应用,基本的.日常的事务处理.例如银行交易. OLT ...