Day Day Code:125. Valid Palindrome有效回文串
125. Valid Palindrome
题目:A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.
Given a string s, return true if it is a palindrome, or false otherwise.
翻译一下:就是有效回文串
思路:
首先将字符串中数字、字母提取出来,并且将所有字母转换为小写,存入新列表。
然后利用双指针解决问题
话不多说上代码
class Solution(object):def isPalindrome(self, s):""":type s: str:rtype: bool"""list=[]#convert numbers and characters and put them in a listfor charc in s:if charc.isalnum():list.append(charc.lower())#convert list to strings="".join(list)#Two-pointersleft = 0right = len(s)-1while left
over.
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
