题目来源


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的更多相关文章

  1. 125. Valid Palindrome【easy】

    125. Valid Palindrome[easy] Given a string, determine if it is a palindrome, considering only alphan ...

  2. 【LeetCode】125. Valid Palindrome 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 列表生成式 正则表达式 双指针 日期 题目地址:https:/ ...

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

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

  4. 【一天一道LeetCode】#125. Valid Palindrome

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

  5. leetcode 125. Valid Palindrome ----- java

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

  6. LeetCode 125. Valid Palindrome

    这个题目只要注意大小写问题即可解决,而且我们只关注的是字母和数值 Given a string, determine if it is a palindrome, considering only a ...

  7. Java [Leetcode 125]Valid Palindrome

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

  8. 【LeetCode】125. Valid Palindrome

    题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ig ...

  9. [leetcode]125. Valid Palindrome判断回文串

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

随机推荐

  1. NOIp 2012 #1 Vigenère 密码 Label:模拟

    题目描述 16 世纪法国外交家 Blaise de Vigenère 设计了一种多表密码加密算法――Vigenère 密 码.Vigenère 密码的加密解密算法简单易用,且破译难度比较高,曾在美国南 ...

  2. 【BZOJ】2286: [Sdoi2011消耗战

    http://www.lydsy.com/JudgeOnline/problem.php?id=2286 题意:n个点的边加权树,m个询问,每次询问给出的k个点与结点1分离的最小代价.(n<=2 ...

  3. 【noiOJ】p8211 (PS:二分浮点数的精度问题)

    05:派 查看 提交 统计 提问 总时间限制:  1000ms 内存限制:  65536kB 描述 我的生日要到了!根据习俗,我需要将一些派分给大家.我有N个不同口味.不同大小的派.有F个朋友会来参加 ...

  4. PHP面向对象学习一

    1. 抽象性 ,  2. 封装性 ,3.共享性 ,4. 强调对象结构而不是程序结构 面向对象的三大特点(封装,继承,多态)缺一不可 class MyPc{ ———创建一个名为 MyPc的类,class ...

  5. 深入浅出-Android系统移植与平台开发(一)- Android4.0系统的下载与编译

    作者:唐老师,华清远见嵌入式学院讲师. 一.Android4.0系统的下载与编译 Android系统的下载与编译,Google的官方网站上已经给出了详细的说明,请参照Android的官方网址: htt ...

  6. Hadoop、Zookeeper、Hbase分布式安装教程

    参考: Hadoop安装教程_伪分布式配置_CentOS6.4/Hadoop2.6.0   Hadoop集群安装配置教程_Hadoop2.6.0_Ubuntu/CentOS ZooKeeper-3.3 ...

  7. GO语言练习:为类型添加方法

    1.代码 2.运行 1.代码 package main import "fmt" type Integer int //给in类型添加 Less 方法,int原来的方法被Integ ...

  8. 总结新系统部署时,Oracle的一些注意事项:

    1.Oracle安装时,要选择字符集为中文编码,数据库重要角色设置密码时,不要用数字开头,不然后面会报一些错误提示 2.emp导出的数据dmp格式,导入时要在服务器导入,具体没有试,要找机会试试,转化 ...

  9. 19.创建如下三个类:(People类中的三个方法分别输出一些信息,ChinaPeople 和AmericanPeople类重写父类的三个方法)。

    package zuoye2; public class People { protected double height; protected double weight; private Stri ...

  10. scala-协变、逆变、上界、下界

    scala-协变.逆变.上界.下界 当我们定义一个协变类型List[A+]时,List[Child]可以是List[Parent]的子类型. 当我们定义一个逆变类型List[-A]时,List[Chi ...