leetcode-easy-string- 125 Valid Palindrome
2024-08-31 21:07:30
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]
最新文章
- (转载)solr时区问题解决方案
- Ubuntu 14.10安装SecureCRT 7.3(转)
- Spring简介和基础
- Supervisor 的配置与使用
- 【转】ubuntu下自动挂载硬盘分区
- win10开始菜单打不开的解决办法
- 一个web应用的诞生(8)--博文发布
- git常用命令总结--廖雪峰老师Git教程命令总结
- Linux:Red Hat系统的安装
- 百度ip定位城市接口调用
- 深入理解HashMap和CurrentHashMap
- AttributeError: 'list' object has no attribute 'keys'
- Mybatis特殊值Enum类型转换器-ValuedEnumTypeHandler
- 从JSF看XPages的优点
- 用 Fiddler 来弥补 Chrome Network 的小缺点
- mysql中and 和 or 联合使用
- LCA在线算法详解
- 轮播图jQuery
- error MSB3552: Resource file ";**/*.resx"; cannot be found. [/ConsoleApp1.csproj]
- 华为手机不能连接android studio进行调试的解决办法