mycode   9.62%

class Solution(object):
def isPalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
res = ''
s = s.lower()
alphanum = string.ascii_lowercase + string.digits
for i in s:
if i in alphanum:
res += i
return res == res[::-1]

注意以下陷阱

class Solution(object):
def isPalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
res = s = [i for i in s if i != ' ']
print(s)
res.reverse()
print(s)
print(res)
return res == s

参考

主要是如何简单的判断是否为字符数组

class Solution(object):
def isPalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
s="".join(e for e in s if e.isalnum()).lower()
return s == s[::-1]

leetcode-easy-string- 125 Valid Palindrome的更多相关文章

  1. 【leetcode❤python】 125. Valid Palindrome

    #-*- coding: UTF-8 -*- class Solution(object):    def isPalindrome(self, s):        ""&quo ...

  2. 125. Valid Palindrome【easy】

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

  3. [LeetCode]题解(python):125 Valid Palindrome

    题目来源 https://leetcode.com/problems/valid-palindrome/ Given a string, determine if it is a palindrome ...

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

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

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

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

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

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

  7. leetcode 125. Valid Palindrome ----- java

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

  8. LeetCode 125. Valid Palindrome

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

  9. Java [Leetcode 125]Valid Palindrome

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

  10. 【LeetCode】125. Valid Palindrome

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

随机推荐

  1. 11 Mysql之配置双主热备+keeepalived.md

    准备 1. 双主 master1 192.168.199.49 master2 192.168.199.50 VIP 192.168.199.52 //虚拟IP 2.环境 master:nginx + ...

  2. vue 组件基本使用

    组件的基本使用 注册组件 注册组件就是利用Vue.component()方法,先传入一个自定义组件的名字,然后传入这个组件的配置.vue.component()注册的全局组件 Vue.componen ...

  3. TKmybatis和mybatisplus哪个好用

    文档连接 :http://baomidou.oschina.io/mybatis-plus-doc/#/?id=%E7%AE%80%E4%BB%8B https://gitee.com/hengboy ...

  4. python的加密方式

    MD5加密 这是一种使用非常广泛的加密方式,不可逆的,在日常字符串加密中经常会用到,下面我简单介绍一下这种方式,主要用到Python自带的模块hashlib,测试代码如下,先创建一个md5对象,然后直 ...

  5. 微信小程序获得高度

    wx.getSystemInfo({ success: (res) => { wx.createSelectorQuery().select('#scrollbox').boundingClie ...

  6. 关于select的取值

    这篇博客,主要是记录我我所犯的错误,或者自己的写法不规范导致了错误,大家可以引以引以为鉴. 我要获取select当前的值,在IE9上我可以直接写document.getElementById(&quo ...

  7. 模拟赛小结:2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017)

    比赛链接:传送门 本场我们队过的题感觉算法都挺简单的,不知道为啥做的时候感觉没有很顺利. 封榜后7题,罚时1015.第一次模拟赛金,虽然是北欧的区域赛,但还是有点开心的. Problem B Best ...

  8. AIX的shell脚本异常笔记

    一点点心得:1.set -x 运行时显示明细,前面加#则不显示2.空格要打好,如if [ -n "str" ]; then 可以,if[ -n "str" ]; ...

  9. mysql导入redis

    将mysql中数据库指定表导入redis 如何将mysql中某个数据库中的表数据快速导入redis? 以下将演示将本地127.0.0.1中数据库test中的表t_abc导入本地redis中.步骤如下: ...

  10. DNS信息探测

    前面学习一下DNS域名解析原理及过程,今天我们学习下DNS域名信息的探测 本章主要目标是从各个角度搜集测试目标的基本信息,包括搜集信息的途径.各种工具的使用方法,以及简单的示例. 0x00 DNS信息 ...