125. Valid Palindrome
来源:互联网 发布:淘宝客挣钱 编辑:程序博客网 时间:2024/06/10 12:39
125. Valid Palindrome
Given a string, determine if it is a palindrome, considering onlyalphanumeric characters and ignoring cases.
For example,
"A man, a plan, a canal: Panama" is a palindrome.
"race a car" is not a palindrome
今天看SVM看的很沮丧。。对自己下一步该怎么走也十分忧愁,毕竟校招已经开始了,各大招聘如火如荼,自己却在这个时候没有着急面试,而是选择转换方向,心里不急是安慰罢了,但还是希望自己能够镇定,不要急不要慌,该来的总会来的。
这里相当于用了两个指针吧,一个从前往后j,一个从后往前end,遍历过程中一旦有不一样的情况就返回False,遍历截止条件是到达中间(这里用//除法,不管总位数是奇数还是偶数,都只取两两对半,不考虑最中间那个数)
class Solution(object): def isPalindrome(self, s): """ :type s: str :rtype: bool """ if s=='': return True s= ''.join([i for i in s if i.isalnum()]) # isalnum() isalpha() s=s.lower() half = (len(s))//2 j=0 end=-1 while j<half: if s[j] != s[end]: return False j+=1 end-=1 return True
阅读全文
0 0
- [LeetCode]125.Valid Palindrome
- LeetCode 125. Valid Palindrome
- [Leetcode] 125. Valid Palindrome
- 【LeetCode】125.Valid Palindrome
- [leetcode] 125.Valid Palindrome
- 125. Valid Palindrome
- [leetcode] 125.Valid Palindrome
- Leetcode 125. Valid Palindrome
- 125. Valid Palindrome
- 125. Valid Palindrome LeetCode
- 125. Valid Palindrome
- 【LeetCode】125. Valid Palindrome
- 125. Valid Palindrome
- 125. Valid Palindrome
- Leetcode 125. Valid Palindrome
- LeetCode 125. Valid Palindrome
- LeetCode 125. Valid Palindrome
- LeetCode *** 125. Valid Palindrome
- 洛谷的题P2038
- Spark History Server 没有生效
- Nodepad++使用技巧
- 64位win7环境eclipse集成svn后出现Failed to load JavaHL Library的解决办法
- 制作AS3语言参考FP26_AIR26_Flex4.7中文API帮助手册chm版下载
- 125. Valid Palindrome
- POJ1904-强连通
- 断言2
- C++动态内存管理
- ORA-30013: undo tablespace 'UNDOTBS1' is currently in use
- C++引用的总结
- 《机器学习》- 支持向量机SVM
- 二维数组的初始化
- 分块算法