zoukankan      html  css  js  c++  java
  • leetcode-easy-string- 125 Valid Palindrome

    mycode   9.62%

    class Solution(object): 
        def isPalindrome(self, s):
            """
            :type s: str
            :rtype: bool
            """
            res = ''
            s = s.lower()
            alphanum = string.ascii_lowercase + string.digits
            for i in s:
                if i in alphanum:
                    res += i
            return res == res[::-1]

    注意以下陷阱

    class Solution(object):
        def isPalindrome(self, s):
            """
            :type s: str
            :rtype: bool
            """
            res = s = [i for i in s if i != ' ']
            print(s)
            res.reverse()
            print(s)
            print(res)
            return res == s

    参考

    主要是如何简单的判断是否为字符数组

    class Solution(object):
        def isPalindrome(self, s):
            """
            :type s: str
            :rtype: bool
            """
            s="".join(e for e in s if e.isalnum()).lower()
            return s == s[::-1]
  • 相关阅读:
    枚举类 --单例模式
    模板设计模式
    动态代理
    反射应用--修改属性值
    通过反射绕过泛型
    java反射
    网络编程练习
    TCP编程
    GUI 聊天界面
    UDP传输多线程
  • 原文地址:https://www.cnblogs.com/rosyYY/p/10996358.html
Copyright © 2011-2022 走看看