题目简述:

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. Swift中类与结构的初始化

    前言:通过学习与研究swift3.0的官方文档关于初始化这部分可以总结为一句话:类与结构是确保一个类型的实例可以使用之前,其所有存储属性都得到了正确的赋值. 一,结构的初始化1 struct Firs ...

  2. ubuntu右上角时间不显示

    重启unity sudo killall unity-panel-service

  3. DX系列之TreeList

    参考资料: DevXpress控件: 第三篇: 将 父子 关系进行到底

  4. HTML5 —— 自学第一课

    1.心得 首先遇见问题要寻根源,而不是将问题抛出:其次要经常查看参考文档.参考示例:学会百度. 2.技能需求 HTML5.XHTML.CSS3.JavaScript.jQuery(jQuery-UI/ ...

  5. Create a new Windows service on windows server2012

    netsh http add iplisten ipaddress=0.0.0.0:15901 sc.exe create "FPPService" binPath= " ...

  6. svn检出的时候报 Unable to connect to a repository at URL错误(摘自CSDN)

    背景:1.         SVN服务器:VisualSVN-Server-2.5.5: 2. SVN客户端:TortoiseSVN-1.7.6.22632-x64-svn-1.7.4.msi: 在S ...

  7. html5第二天

    哎..以为自己能每天坚持写呢.前面8天一直在D3的东西..都没有时间研究html5.草草的翻了一下HTML5和CSS3权威指南.对整个页面设计有了一个大概的把握,但是让自己做肯定还会有写问题.暂时ht ...

  8. 使用stack的思考

    对于使用stack进行()的配对检查,不需要使用额外的空间对每个字符进行存储和push与pop的操作. 只使用size对()进行处理即可,因为只有一种括号,所以入栈为size加1,出栈为size-1. ...

  9. ios显示一个下载banner

    <meta name="apple-itunes-app" content="app-id=432274380" /> 这个标签是告诉iphone的 ...

  10. 我的C语言进化史

    Hello, world! 这三年就看看我的C语言还有JAVAscript进化史吧.更厉害的sunmarvell,我等你