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. CSS行高——line-height 垂直居中等问题

    CSS行高——line-height   初入前端的时候觉得CSS知道display.position.float就可以在布局上游刃有余了,随着以后工作问题层出不穷,才逐渐了解到CSS并不是几个sty ...

  2. less 经典范例 bootstrap 的 less 版本 常用 less 代码

    1. bootstrap 的 less 版本 2.less 文件分布 /*! * Bootstrap v3.3.7 (http://getbootstrap.com) * Copyright 2011 ...

  3. mysql设置自增id清零 auto_increment

    清空表数据之后,如何让自增id清零,即从0开始计数呢 ; 想让id从1开始,就让 AUTO_INCREMENT = 1 就行了.

  4. [易学易懂系列|rustlang语言|零基础|快速入门|(19)|多线程]

    [易学易懂系列|rustlang语言|零基础|快速入门|(19)|多线程] 实用知识 多线程 我们今天来讲讲Rust中的多线程. 我直接来看看代码: use std::thread; use std: ...

  5. exec模块,元类与ORV的应用

    exec模块的补充 1.是什么? exec是一个Python内置模块. 2.exec的作用: ''' x = 10 def func1(): pass ''' 可以把"字符串形式" ...

  6. DevExpress ASP.NET Bootstrap v19.1版本亮点:Editors控件

    行业领先的.NET界面控件DevExpress 正式发布了v19.1版本,本文将以系列文章的方式为大家介绍DevExpress ASP.NET Bootstrap Controls中Editors.G ...

  7. 【BZOJ 3682】Phorni

    题目链接 题目描述 Phorni 是一个音之妖精,喜欢在你的打字机上跳舞. 一天,阳光映射到刚刚淋浴过小雨的城市上时,Phorni 用魔法分裂出了许多个幻影,从 1 到 n 编号. 她的每一个幻影都站 ...

  8. SessionFactory的openSession与getCurrentSession区别

    SessionFactory 1 用来产生和管理sesssion 2 通常情况下,每个应用只需要一个SessionFactory,除非要访问多个数据库的情况 3 openSession()与openS ...

  9. 【leetcode】1243. Array Transformation

    题目如下: Given an initial array arr, every day you produce a new array using the array of the previous ...

  10. 【leetcode】1254. Number of Closed Islands

    题目如下: Given a 2D grid consists of 0s (land) and 1s (water).  An island is a maximal 4-directionally ...