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. NativeScript —— 初级入门(跨平台的手机APP应用)《二》

    NativeScript项目结构 根文件夹 package.json —— 这是适用于整个应用程序的NativeScript主项目配置文件. 它基本概述了项目的基本信息和所有平台要求. 当您添加和删除 ...

  2. Web前端开发解耦1

    在网站建设的工作中,Web前端工程师占据着非常重要的位置,好的前端工程师保证了良好的网站优化以及友好的用户体验.今天佚站互联主要分享一下对于Web前端开发规范的一些见解. 学过面向对象编程的朋友应该都 ...

  3. Django 数据库模块 单独使用

    pip install django pip install psycopg2 pip install mysqlclient Entity.py from django.db import mode ...

  4. SDRAM介绍

    一.             介绍 存储器的最初结构为线性,它在任何时刻,地址线中都只能有一位有效.设容量为N×M的存储器有S0-Sn-1条地址线:当容量增大时,地址选择线的条数也要线性增多,利用地址 ...

  5. 记一次部署PHP遇到的编码问题故障

    php开发给我项目和数据库,我按正常部署流程部署,开始发现之梦的后台登陆不了,后发现是属主属组不对,代码直接解压后是root的,更改后,后台能登陆,但部分显示乱码.后将正常的数据库文件重新导入后,显示 ...

  6. 跟着动画来学习TCP三次握手和四次挥手

    TCP三次握手和四次挥手的问题在面试中是最为常见的考点之一.很多读者都知道三次和四次,但是如果问深入一点,他们往往都无法作出准确回答. 点我查看如何应对面试中的三次握手.四次挥手 本篇尝试使用动画来对 ...

  7. lightinthebox程序bug zencart

    1.清空旧产品分类,新增分类与产品,前台首页不显示中间栏,提示无产品:布局设置 -(Main Page - Opens with Category)首页显示某分类,把新增的某分类ID填上或者设为0即可 ...

  8. shoeBox超实用的雪碧图(Sprite)图制作工具-使用

    从前端优化说起 浏览器载入单张图片的速度基本取决于图片的大小,但是载入多张图片的速度却和另一个要素息息相关-网络请求数,在图片大小和一致的情况下,图片张数越少其请求数越少其载入速度也就越快.所以在使用 ...

  9. Python核心技术与实战——十九|一起看看Python全局解释器锁GIL

    我们在前面的几节课里讲了Python的并发编程的特性,也了解了多线程编程.事实上,Python的多线程有一个非常重要的话题——GIL(Global Interpreter Lock).我们今天就来讲一 ...

  10. Codeforces Round #608 (Div. 2) E. Common Number

    链接: https://codeforces.com/contest/1271/problem/E 题意: At first, let's define function f(x) as follow ...