[LeetCode]题解(python):125 Valid Palindrome
题目来源
https://leetcode.com/problems/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.
题意分析
Input: a string
Output: whether the string is valid palindrome
Conditions: 判断是否是回文串,忽略非数字和非字母的字符
题目思路
采用isalnum来判断是否为字母或数字,然后将字符转为小写(题目认为大小写是一样的),然后简单判断是否是回文。
AC代码(Python)
class Solution(object):
def isPalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
c = []
for i in s:
if i.isalnum():
c.append(i.lower())
for i in range(len(c)/2):
if c[i] != c[len(c)-1-i]:
return False
return True
[LeetCode]题解(python):125 Valid Palindrome的更多相关文章
- 125. Valid Palindrome【easy】
125. Valid Palindrome[easy] Given a string, determine if it is a palindrome, considering only alphan ...
- 【LeetCode】125. Valid Palindrome 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 列表生成式 正则表达式 双指针 日期 题目地址:https:/ ...
- [LeetCode] 125. Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- 【一天一道LeetCode】#125. Valid Palindrome
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- leetcode 125. Valid Palindrome ----- java
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 a ...
- Java [Leetcode 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 ig ...
- [leetcode]125. Valid Palindrome判断回文串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
随机推荐
- java基础-表达式,语句和代码块
浏览以下内容前,请点击并阅读 声明 表达式 表达式由变量,操作符和方法调用组成,表达式的返回值类型由表达式中的元素(如操作符,变量等)决定如: cadence = 0 上述代码将返回一个int类型的值 ...
- soapui中文操作手册(一)----创建一个新的项目
1) 创建一个新的项目 点击项目,选择新建项目SOAP.这将打开一个新的SOAP项目对话框. 注意:你也可以做CTRL + N(WIN)或CMD+ N(MAC)来创建一个新的SOAP项目. 在新的SO ...
- BZOJ4662 : Snow
首先离散化,即相邻关键点之间的部分可以压成一段. 注意到区间互不包含,因此排序后每个位置的清理影响到的是一段连续区间的清理工的工作长度. 这显然可以用线段树维护,支持区间减去一个数,单点加上$inf$ ...
- hive :MetaException(message:Version information not found in metastore. )
MetaException(message:Version information not found in metastore. ) Hive now records the schema vers ...
- sed 格式化输出df -h
df -h|sed '1d;/ /!N;s/\n//;s/ \+/ /;' 1d——————删除第一行 / /!N——————没有空格的行执行N 例子中没有空格的行 /dev/mapper/vg_ds ...
- Codeforces Testing Round #10 B. Balancer
水题,只要遍历一遍,不够平均数的,从后面的借,比平均数多的,把多余的数添加到后面即可,注意数据范围 #include <iostream> #include <vector> ...
- ACM 蛇形填数
蛇形填数 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 在n*n方陈里填入1,2,...,n*n,要求填成蛇形.例如n=4时方陈为:10 11 12 19 16 1 ...
- 《DON'T MAKE ME THINK》/《点石成金访客至上的网页设计秘笈》 读书笔记
1.web页面要尽可能简单,让用户不用思考就能知道页面的功能,如果要进行一些崭新的.开拓性的或者非常复杂的页面设计时, 此时要利用页面元素的外观.精心选择的名称.页面布局以及少量仔细斟酌过的文字,使页 ...
- InterBase数据库迁移到MySQL(恢复备份)
我拿到的是InterBase导出的“.gbk”后缀的数据库备份文件,目标是可以通过命令行的方式导入到指定的数据库中,在这个脚本中我使用了InterBase数据库中自带的“gbak”命令行来进行操作. ...
- ajax操作时用于提高用户体验的两段备用代码
<div id="msgBoxDIV" style="position: absolute; width: 50%; padding-top: 2px; heigh ...