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 划分字符串的回文串子串: 简单 ...
随机推荐
- 给jdk配置jvm的参数
(1)window->preference->java->installed JREs ->edit -Xms512m -Xmx512m -XX:MaxNewSize=512 ...
- C++ 类的多态五(多态的语法本质分析)
//多态的语法本质分析 #include<iostream> using namespace std; /* 三种易混淆的多态场景 */ class Point{ public: Poin ...
- JavaScript 严格模式(use strict)
前言: "use strict" 指令在 JavaScript 1.8.5 (ECMAScript5) 中新增. 它不是一条语句,但是是一个字面量表达式,在 JavaScript ...
- [CB2]start up
1.更新源 From:http://cubie.cc/forum.php?mod=viewthread&tid=3054&extra= sudo emacs 打开/etc/apt/so ...
- 【PyQt】算法-插入、递归、冒泡
# coding=utf-8 import sys from PyQt4.QtGui import * from PyQt4.QtCore import * class MainWindow(QMai ...
- c++新特性---引用变量
一.定义 引用变量是已定义变量的别名,如将ra设置为a的引用变量,则可以使用ra和a交替使用该变量. 表示: int a = 5; int & ra = a; 其中&不是地址运算符,而 ...
- CKEDITOR 3.4.2中 按钮事件中 动态改变图标和title 获取按钮
this.uiItems[0].className="cke_button_hui_position_type";this.uiItems[0].title="zhang ...
- 【BZOJ2090/2089】[Poi2010]Monotonicity 2 动态规划+线段树
[BZOJ2090/2089][Poi2010]Monotonicity Description 给出N个正整数a[1..N],再给出K个关系符号(>.<或=)s[1..k].选出一个长度 ...
- Webservice工作原理及实例
Web Service工作原理及实例 一.Web Service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者In ...
- crash处理core文件
(一时心血来潮总结的,供大家参考,时间仓促,不足之处勿拍砖,欢迎讨论~)Crash工具用于解析Vmcore文件,Vmcore文件为通过kdump等手段收集的操作系统core dump信息,在不采用压缩 ...