题目简述:

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:
# @param s, a string
# @return a boolean
def isPalindrome(self, s):
if s == '':
return True s = s.strip().lower()
t = ''
for i in s:
if (i <= '9' and i >= '0') or (i <= 'z' and i >= 'a'):
t += i l = len(t)
for i in range(l/2): if t[i] != t[l-i-1]:
return False
return True

【leetcode】Valid Palindrome的更多相关文章

  1. 【题解】【字符串】【Leetcode】Valid Palindrome

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  2. 【LeetCode】- Valid Palindrome(右回文)

    [ 问题: ] Given a string, determine if it is a palindrome, considering only alphanumeric characters an ...

  3. 【leetcode】Valid Palindrome II

    很久没有做题了,今天写个简单难度的练练手感. Given a non-empty string s, you may delete at most one character. Judge wheth ...

  4. 【Leetcode】【Easy】Valid Palindrome

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  5. 【LeetCode】9. Palindrome Number (2 solutions)

    Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. click t ...

  6. 【leetcode】1278. Palindrome Partitioning III

    题目如下: You are given a string s containing lowercase letters and an integer k. You need to : First, c ...

  7. 【LeetCode】336. Palindrome Pairs 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 HashTable 相似题目 参考资料 日期 题目地 ...

  8. 【LeetCode】9. Palindrome Number 回文数

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:回文数,回文,题解,Leetcode, 力扣,Python ...

  9. 【LeetCode】234. Palindrome Linked List 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

随机推荐

  1. (error) MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk

    今天运行Redis时发生错误,错误信息如下: (error) MISCONF Redis is configured to save RDB snapshots, but is currently n ...

  2. win tomcat

    D:\tomcat8080\binstartup.bat rem ------------------------------------------------------------------- ...

  3. 解决jeecg包升级之后无法启动的问题

    1.出现下述问题的解决办法. 解决包冲突问题,右键项目,选择properties 把lib目录下的jar吧添加上.remove调版本较低的包即可. 2. 解决方法,把jdk升级到1.7版本

  4. 《锋利的jQuery(第2版)》笔记-第1章-认识jQuery

    jQuery是随着Web2.0兴起的JavaScript库之一,因为其独特的优点,受到越来越多人的追捧! 1.1 JavaScript和JavaScript库 1.1.1 JavaScript简介 J ...

  5. 【WP8.1】类似“IT之家” 自定义消息 的实现

    曾经在WP7.WP8下的消息 使用的都是Coding4Fun.Phone.Toolkit里面的ToastPrompt类来实现的. 现在我们来自己做个类似IT之家的这种效果:从右边弹出,经过几秒后会自动 ...

  6. 学习实战java虚拟机的计划图

    啥也不说了,实战java虚拟机,好好学习,天天向上! <实战java虚拟机>一书Q交流群:397196583

  7. hdu4405 Aeroplane chess

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  8. sqlserver 2005 数据误删恢复

    今天同事不小心将一个很重要的数据表中的数据删除了,找了很多人都没办法恢复.我在网上搜索了一下资料,发现有一个方法可以一试,具体如下 http://www.knowsky.com/616730.html ...

  9. HDU4411 最小费用流

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4411 floyd处理出最短路 每个点拆为i.i+n,i到i+n连一条容量为1,费用为负无穷的边,代表这个城 ...

  10. Ajax商品分类三级联动实现

    思路分析: 效果:当页面加载时,利用ajax异步向后台请求数据,加载一级商品类别,当选择一级商品时加载二级商品,选择二级商品加载三级商品. 实现: 1.当拿到数据后加载pid为0的商品,并动态创建op ...