[勇者闯LeetCode] 125. Valid Palindrome

Description

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

For example,
"A man, a plan, a canal: Panama" is a palindrome.
"race a car" is not a palindrome.

Note:
Have you consider that the string might be empty? This is a good question to ask during an interview.

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

Information

  • Tags: Tow Pointers | String
  • Difficulty: Easy

Solution

使用两个指针分别从字符串的首尾开始扫描,若两个指针所指向的字母不相等则返回False,否则分别寻找下一个字母进行比较,当两个指针相遇时返回True。

Python Code

class Solution(object):def isPalindrome(self, s):""":type s: str:rtype: bool"""left, right = 0, len(s)-1while left < right:while left < right and not s[left].isalnum():left += 1while left < right and not s[right].isalnum():right -= 1if s[left].lower() != s[right].lower():return Falseleft += 1right -= 1return True

[勇者闯LeetCode] 125. Valid Palindrome相关推荐

  1. 【回文串3】LeetCode 125. Valid Palindrome

    LeetCode 125. Valid Palindrome Solution1:我的答案 复杂度为O(n)O(n)O(n),写法不是很简练啊. class Solution { public:boo ...

  2. LeetCode 125 Valid Palindrome(有效回文)(*)

    版权声明:转载请联系本人,感谢配合!本站地址:http://blog.csdn.net/nomasp https://blog.csdn.net/NoMasp/article/details/5062 ...

  3. LeetCode 125. Valid Palindrome

    题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ig ...

  4. 125 Valid Palindrome

    125 Valid Palindrome 链接:https://leetcode.com/problems/valid-palindrome/ 问题描写叙述: Given a string, dete ...

  5. 【回文串14】LeetCode 680. Valid Palindrome II

    LeetCode 680. Valid Palindrome II Solution1:我的答案 复杂度是O(n)O(n)O(n),不算好啊.. 注意:对于c++中string对象常用的insert( ...

  6. [勇者闯LeetCode] 1. Two Sum

    [勇者闯LeetCode] 1. Two Sum Description Given an array of integers, return indices of the two numbers s ...

  7. [勇者闯LeetCode] 6. ZigZag Conversion

    [勇者闯LeetCode] 6. ZigZag Conversion Description The string "PAYPALISHIRING" is written in a ...

  8. [勇者闯LeetCode] 70. Climbing Stairs

    [勇者闯LeetCode] 70. Climbing Stairs Description You are climbing a stair case. It takes n steps to rea ...

  9. [勇者闯LeetCode] 112. Path Sum

    [勇者闯LeetCode] 112. Path Sum Description Given a binary tree and a sum, determine if the tree has a r ...

最新文章

  1. Codeforces 1408 D. Searchlights(优化DP、思维)
  2. 苹果6屏幕多大_相较前段新鲜感满满,谈谈苹果12这几天的实际感受
  3. Shell中的Wget 的用法
  4. IDEA工具创建项目并提交码云和一些基本使用
  5. github密码格式_如何使用GitHub构建一个简单的网页 (不用框架版本)
  6. 二叉搜索树简介和部分题目
  7. 【学习笔记】系统观核心管理理论
  8. OpenGL ES之3D渲染旋转的贴图立方体
  9. 在 SELECT 查询中使用透视
  10. Eclipse 快捷键 查看方法在那里被调用~
  11. HDU 5834 Magic boy Bi Luo with his excited tree 树形DP
  12. googel的扩展插件导出与导入
  13. tomcat的目录结构
  14. JAVA笔记20-容器之四Map接口、自动打包、泛型(重要)
  15. 药物临床试验数据递交PMDA的规定
  16. 玉米社:短视频运营主要做哪些工作?
  17. css定位-css新增选择器(内减,属性,伪类,2d变换,过渡)
  18. python报错: arry[i] = t IndexError: list assignment index out of range
  19. Google Earth Engine(GEE)——
  20. 奇虎360 2013校园招聘笔试题

热门文章

  1. 万用表测量电阻时电路板为什么需要断电
  2. html h1 不自动加粗,HTML之h1 h2 h3 h4标签知识经验篇
  3. matlab实现中值滤波程序,中值滤波流程(matlab平滑滤波和中值滤波程序)
  4. FaaS,未来的后端服务开发之道
  5. 创业板面世对本土微电子界的影响
  6. 如何通过软文营销获得流量红利?
  7. Linux如何卸载slurm,RedHat安装SLURM
  8. MUI框架详解-全面讲解MUI框架使用
  9. DETR代码学习(五)之匈牙利匹配
  10. 转载:程序员应知——团队精神