原题地址: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. 括弧匹配检验(check.cpp)

    [问题描述]        假设表达式中允许包含两种括号:圆括号和方括号,其嵌套的顺序随意,如([ ]())或[([ ][ ])]等为正确的匹配,[( ])或([ ]( )或 ( ( ) ) )均为错 ...

  2. 牛客网某比赛 I 小乐乐学博弈 博弈论

    题目大意: 有两堆石子\(n\)和\(m\),每次可以拿\(1 \sim k\)个 \(k >= |n - m|\) 问先手必胜? 把限制条件去掉才有意思 首先考虑两堆相等,那么先手怎么操作,后 ...

  3. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem D. Distance 迪杰斯特拉

    Problem D. Distance 题目连接: http://codeforces.com/gym/100714 Description In a large city a cellular ne ...

  4. URAL 1962 In Chinese Restaurant 数学

    In Chinese Restaurant 题目连接: http://acm.hust.edu.cn/vjudge/contest/123332#problem/B Description When ...

  5. Linux学习笔记01—安装LInux系统

    1.首先,使用光驱或U盘或你下载的Linux ISO文件进行安装. 界面说明: Install or upgrade an existing system 安装或升级现有的系统 install sys ...

  6. Java 与 .NET 的平台发展之争

    Java 8即将正式发布,从早期版本中,我们已经可以领略到一些令人兴奋的特性.但是开发者Andrew C. Oliver表示,尽管如此,Java语言在某些特性上还是落后于.Net.比如,Java 8中 ...

  7. 下载8000首儿歌的python代码

    下载8000首儿歌的python的代码: #-*- coding: UTF-8 -*- from pyquery import PyQuery as py from lxml import etree ...

  8. Introduction to the Optimizer --cbo

    http://docs.oracle.com/cd/B10500_01/server.920/a96533/optimops.htm

  9. 学一点 MYSQL 双机异地热备份—-MYSQL主从,主主备份原理及实践

    简单介绍mysql双机,多机异地热备简单原理实战. 双机热备的概念简单说一下,就是要保持两个数据库的状态自动同步.对任何一个数据库的操作都自动应用到另外一个数据库,始终保持两个数据库数据一致. 这样做 ...

  10. 查看内核页表kernel_page_tables (aarch32)

    作者 彭东林 pengdonglin137@163.com   平台 Linux-4.10.17 Qemu + vexpress-ca9     概述 通过配置内核,会在/sys/kernel/deb ...