原题地址:https://oj.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.

解题思路:将不是字母的字符去掉,然后转换成小写,然后简单的回文判断。

代码:

class Solution:
# @param s, a string
# @return a boolean
def isPalindrome(self, s):
if s == '':
return True
else:
sTmp = ''
for i in range(0, len(s)):
if s[i] >= 'a' and s[i] <= 'z' or s[i] >= '' and s[i] <= '' or s[i] >= 'A' and s[i] <= 'Z':
sTmp += s[i]
sTmp = sTmp.lower()
for i in range(0, len(sTmp)/2):
if sTmp[i] != sTmp[len(sTmp)-1-i]:
return False
return True

[leetcode]Valid Palindrome @ Python的更多相关文章

  1. leetcode Valid Palindrome C++&amp;python 题解

    题目描写叙述 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...

  2. [LeetCode] Valid Palindrome 验证回文字符串

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

  3. LeetCode——Valid Palindrome

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

  4. [LeetCode] Valid Palindrome II 验证回文字符串之二

    Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...

  5. LeetCode Valid Palindrome II

    原题链接在这里:https://leetcode.com/problems/valid-palindrome-ii/description/ 题目: Given a non-empty string  ...

  6. Leetcode Valid Palindrome

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

  7. LeetCode: Valid Palindrome [125]

    [题目] Given a string, determine if it is a palindrome, considering only alphanumeric characters and i ...

  8. LeetCode: Valid Palindrome 解题报告

    Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric char ...

  9. [Leetcode] valid palindrome 验证回文

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

随机推荐

  1. UVALive 6907 Body Building tarjan

    Body Building 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8 ...

  2. android.os.handler(转)

    android.os.handler相关知识整理 Handler在android里负责发送和处理消息.它的主要用途有: 1)按计划发送消息或执行某个Runnanble(使用POST方法): 2)从其他 ...

  3. 使用Apache commons-codec Base64实现加解密(转)

    commons-codec是Apache下面的一个加解密开发包 官方地址为:http://commons.apache.org/codec/ 官方下载地址:http://commons.apache. ...

  4. python实例[判断操作系统类型]

    参考文献:http://bbs.chinaunix.net/thread-1848086-1-1.html 经常地我们需要编写跨平台的脚本,但是由于不同的平台的差异性,我们不得不获得当前所工作的平台( ...

  5. linux网络编程:splice函数和tee( )函数高效的零拷贝

    splice( )函数 在两个文件描述符之间移动数据,同sendfile( )函数一样,也是零拷贝. 函数原型: #include <fcntl.h> ssize_t splice(int ...

  6. 在 DELPHI 中 procedure 型变量与 method 型变量的区别

    Procedure型变量: 在DELPHI中,函数.过程的地址可以赋给一个特殊类型的变量,变量可用如下方式声明: var p : procedure(num:integer); //过程 或: var ...

  7. <c:otherwise>

    <c:if>没有<c:else>可以用<c:choose>来取代结构:<c:choose> <c:when test=""&g ...

  8. 【CentOS】centos如何修改你的主机名

    转载地址:https://www.linuxidc.com/Linux/2014-11/109238.htm ============================================= ...

  9. 在Activity中使用Thread导致的内存泄漏

    https://github.com/bboyfeiyu/android-tech-frontier/tree/master/issue-7/%E5%9C%A8Activity%E4%B8%AD%E4 ...

  10. IntentService 与ResultReceiver

    from://http://lyzhanghai.iteye.com/blog/947504 在google的I/O大会中关于“Writing zippy Android apps”,有讲过用Inte ...