125. 验证回文串【isalnum()】

125. 验证回文串【isalnum()】

class Solution(object):
    def isPalindrome(self, s):
        """
        :type s: str
        :rtype: bool
        """
        s = s.lower()
        # print(s)
        news = ""
        # s[1].is
        for i in range(len(s)):
            if s[i].isalnum(): # 题目要求:只考虑字母和数字字符
                news+=s[i]
        # print(news)
        # news = 'aba'
        length = len(news)
        for i in range(length//2):
            if news[i] != news[length-i-1]:
                return False
        return True

 

相关文章:

  • 2021-05-02
  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
  • 2021-06-24
  • 2022-01-09
  • 2021-07-25
  • 2022-01-24
猜你喜欢
  • 2021-09-01
  • 2021-10-14
  • 2022-03-02
  • 2021-11-05
  • 2021-07-13
相关资源
相似解决方案