【leetcode】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.
解题思路:
class Solution:
# @param s, a string
# @return a boolean
def isPalindrome(self, s):
if s == '':
return True
s = s.strip().lower()
t = ''
for i in s:
if (i <= '9' and i >= '0') or (i <= 'z' and i >= 'a'):
t += i
l = len(t)
for i in range(l/2):
if t[i] != t[l-i-1]:
return False
return True
【leetcode】Valid Palindrome的更多相关文章
- 【题解】【字符串】【Leetcode】Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- 【LeetCode】- Valid Palindrome(右回文)
[ 问题: ] Given a string, determine if it is a palindrome, considering only alphanumeric characters an ...
- 【leetcode】Valid Palindrome II
很久没有做题了,今天写个简单难度的练练手感. Given a non-empty string s, you may delete at most one character. Judge wheth ...
- 【Leetcode】【Easy】Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- 【LeetCode】9. Palindrome Number (2 solutions)
Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. click t ...
- 【leetcode】1278. Palindrome Partitioning III
题目如下: You are given a string s containing lowercase letters and an integer k. You need to : First, c ...
- 【LeetCode】336. Palindrome Pairs 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 HashTable 相似题目 参考资料 日期 题目地 ...
- 【LeetCode】9. Palindrome Number 回文数
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:回文数,回文,题解,Leetcode, 力扣,Python ...
- 【LeetCode】234. Palindrome Linked List 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
随机推荐
- 二维码相关---java生成二维码名片,并且自动保存到手机通讯录中...
http://blog.csdn.net/lidew521/article/details/24441825
- word2vec参数调整 及lda调参
一.word2vec调参 ./word2vec -train resultbig.txt -output vectors.bin -cbow 0 -size 200 -window 5 -neg ...
- codevs1257 打砖块
题目描述 Description 在一个凹槽中放置了n层砖块,最上面的一层有n块砖,第二层有n-1块,--最下面一层仅有一块砖.第i层的砖块从左至右编号为1,2,--i,第i层的第j块砖有一个价值a[ ...
- Xcode 快捷键、常用技巧
关于iOS开发中的技能快捷键 经常使用鼠标太TM的D疼了,快捷键能大大地提高我们的开发速度,使我们的手指尽情的在键盘上飞舞,优美的代码,哈哈哈,那些常规的复制.粘贴.剪切请自行度娘或者Google一下 ...
- c语言经典算法—求0—7 所能组成的奇数个数
题目:求0—7 所能组成的奇数个数. 算法思想:这个问题其实是一个排列组合的问题,设这个数为sun=a1a2a3a4a5a6a7a8,a1-a8表示这个数的某位的数值,当一个数的最后一位为奇数时,那么 ...
- c语言经典算法——猴子偷桃问题
题目:海滩上有一堆桃子,五只猴子来分.第一只猴子把这堆桃子凭据分为五份,多了一个,这只猴子把多的一个扔入海中,拿走了一份.第二只猴子把剩下的桃子又平均分成五份,又多了一个,它同样把多的一个扔入海中,拿 ...
- laravel强大功能路由初探(二)
目标当然是先输出helloworld 配置hosts文件和apache下的httpd-vhosts.conf, hosts:127.0.0.1 www.blog.com httpd-vhosts.c ...
- vue2/vuex2的那点坑
说是坑,其实大部分是我们自己的过错! vuex官方demo在1.0可以运行,在2.0报错?此类问题,应该很常见吧? 还有顺溜的利用1.0搭建的webpack编译环境到了vue2.0突然失效了,报错了? ...
- MySQL 应用优化
一.使用连接池 二.减少对MySQL的访问 (A) 避免对同一数据做重复检索. (B) 使用查询缓存,MySQL的查询缓存会存储SELECT查询的命令文本和相应的结果. (C) 增加CACHE层 三. ...
- sublime text快捷键
Ctrl+Shift+V:粘贴并格式化Ctrl+D:选择单词,重复可增加选择下一个相同的单词Ctrl+L:选择行,重复可依次增加选择下一行Ctrl+M:跳转到对应括号Ctrl+K+B:开关侧栏Ctrl ...