1、注意空字符串的处理;

2、注意是alphanumeric字符;

3、字符串添加字符直接用+就可以;

  1. class Solution:
  2. # @param s, a string
  3. # @return a boolean
  4. def isPalindrome(self, s):
  5. ret = False
  6. s = s.lower()
  7. ss = ""
  8. for i in s:
  9. if i.isalnum():
  10. ss += i
  11. h = 0
  12. e = len(ss)-1
  13. while(h<e):
  14. if(ss[h] == ss[e]):
  15. h += 1
  16. e -= 1
  17. else:
  18. break
  19. if h>=e:
  20. ret = True
  21. return ret

leetcode:Valid Palindrome【Python版】的更多相关文章

  1. [leetcode]Valid Palindrome @ Python

    原题地址:https://oj.leetcode.com/problems/valid-palindrome/ 题意: Given a string, determine if it is a pal ...

  2. leetcode Valid Palindrome C++&amp;python 题解

    题目描写叙述 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...

  3. [LeetCode] Valid Palindrome 验证回文字符串

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

  4. LeetCode——Valid Palindrome

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

  5. [LeetCode] Valid Palindrome II 验证回文字符串之二

    Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...

  6. LeetCode Valid Palindrome II

    原题链接在这里:https://leetcode.com/problems/valid-palindrome-ii/description/ 题目: Given a non-empty string  ...

  7. Leetcode Valid Palindrome

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

  8. LeetCode: Valid Palindrome [125]

    [题目] Given a string, determine if it is a palindrome, considering only alphanumeric characters and i ...

  9. LeetCode: Valid Palindrome 解题报告

    Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric char ...

  10. [Leetcode] valid palindrome 验证回文

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

随机推荐

  1. English trip -- Review Unit8 Work 工作

    工作一般询问对方的工作情况的方式: What job is it?  它的工作是什么? You're a engineer?     你是工程师? Right  是的 What do you do?  ...

  2. 20170501xlVBA销售订单整理一行转多行

    Sub NextSeven_CodeFrame() Application.ScreenUpdating = False Application.DisplayAlerts = False Appli ...

  3. 2018焦作网络赛Give Candies

    一开始忽略了欧拉定理指数部分是modphi(n-1)没有memset,减法后面没加0:

  4. CF1083B The Fair Nut and String

    题意 给出两个长度为n的01字符串S和T. 选出k个字典序在S和T之间的长度为n的01字符串,使得尽可能多的字符串满足其是所选字符串中至少一个串的前缀. 这是一道思路比较奇怪的类似计数dp的题. 首先 ...

  5. Python下尝试实现图片的高斯模糊化

    资源下载 #本文PDF版下载Python下尝试实现图片的高斯模糊化#本文代码下载高斯模糊代码下载 高斯模糊是什么? (先来看一下维基百科对它的定义) 高斯模糊是模糊图像的结果.它是一种广泛使用的图形软 ...

  6. IntelliJ IDEA 自动导入包 快捷方式 关闭重复代码提示

    idea可以自动优化导入包,但是有多个同名的类调用不同的包,必须自己手动Alt+Enter设置 设置idea导入包 勾选标注 1 选项,IntelliJ IDEA 将在我们书写代码的时候自动帮我们优化 ...

  7. Oracle12cr1新特性之容器数据库(CDB)和可插拔数据库(PDB) 的启动和关闭

    Oracle12c中引入的多宿主选项(multitenant option)允许一个容器数据库容纳多个独立的可插拔数据库(PDB).本文将说明如何启动和关闭容器数据库(CDB)和可插拔数据库(PDB) ...

  8. vue2.0对不同数据类型的显示

  9. 桥接、nat、host-only

  10. UVALive 5107 dfs暴力搜索

    题目链接:A hard Aoshu Problem DES:给三个字符串,包含的字符是A-E范围内的.长度都不超过8.每个字符可以而且只可以匹配一个数字.两个字符不能匹配相同的数字.前两个式子之间可以 ...