LeetCode Valid Palindrome Python
2015-03-28 19:02
323 查看
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): ls = [i.lower() for i in s if i.isalnum()] l = len(ls) tmp1 = ls[:l/2] tmp2 = list(reversed(ls[l/2:] if l%2==0 else ls[l/2+1:])) return True if tmp1==tmp2 else False
相关文章推荐
- [leetcode]Valid Palindrome @ Python
- [leetcode] Valid Palindrome @ Python
- leetcode Valid Palindrome C++&python 题解
- 【leetcode】680. Valid Palindrome II(Python & C++)
- leetcode Valid Palindrome C++&python 题解
- Valid Palindrome Leetcode Python
- 【leetcode】valid-palindrome
- Valid Palindrome leetcode java
- [leetcode:python]20.Valid Parentheses
- leetcode--Python正则表达式解析Valid Phone nums
- LeetCode Valid Palindrome
- Leetcode: Valid Palindrome
- [LeetCode]题解(python):132-Palindrome Partitioning II
- LeetCode Valid Palindrome
- leetcode之Valid Palindrome
- Leetcode-680. Valid Palindrome II(判断回文)
- 【leetcode】20. Valid Parentheses(Python & C++)
- Leetcode_valid-number(updated c++ and python version)
- Leetcode Day5 20. Valid Parentheses Python 栈的实现
- leetcode 日经贴,python code -Valid Parentheses