zoukankan      html  css  js  c++  java
  • 125. Valid Palindrome

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

    Note: For the purpose of this problem, we define empty string as valid palindrome.

    Example 1:

    Input: "A man, a plan, a canal: Panama"
    Output: true

    Example 2:

    Input: "race a car"
    Output: false

    class Solution:
        def isPalindrome(self, s):
            """
            :type s: str
            :rtype: bool
            """
            if len(s)==0:
                return True
            str = []
            for i in s:
                if i.isalnum():
                    str.append(i.lower())
            for i in range(int(len(str)/2)):
                if str[i]!= str[len(str)-i-1]:
                    return False
            return True
    
  • 相关阅读:
    Day10
    Day9
    Day8
    Day 7
    Day-6
    java中的原子性
    java 原子性
    内存可见性
    JVM 常忘笔记
    JVM 解释执行 编译执行 JIT
  • 原文地址:https://www.cnblogs.com/bernieloveslife/p/9733355.html
Copyright © 2011-2022 走看看