[勇者闯LeetCode] 125. Valid Palindrome
[勇者闯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相关推荐
- 【回文串3】LeetCode 125. Valid Palindrome
LeetCode 125. Valid Palindrome Solution1:我的答案 复杂度为O(n)O(n)O(n),写法不是很简练啊. class Solution { public:boo ...
- LeetCode 125 Valid Palindrome(有效回文)(*)
版权声明:转载请联系本人,感谢配合!本站地址:http://blog.csdn.net/nomasp https://blog.csdn.net/NoMasp/article/details/5062 ...
- LeetCode 125. Valid Palindrome
题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ig ...
- 125 Valid Palindrome
125 Valid Palindrome 链接:https://leetcode.com/problems/valid-palindrome/ 问题描写叙述: Given a string, dete ...
- 【回文串14】LeetCode 680. Valid Palindrome II
LeetCode 680. Valid Palindrome II Solution1:我的答案 复杂度是O(n)O(n)O(n),不算好啊.. 注意:对于c++中string对象常用的insert( ...
- [勇者闯LeetCode] 1. Two Sum
[勇者闯LeetCode] 1. Two Sum Description Given an array of integers, return indices of the two numbers s ...
- [勇者闯LeetCode] 6. ZigZag Conversion
[勇者闯LeetCode] 6. ZigZag Conversion Description The string "PAYPALISHIRING" is written in a ...
- [勇者闯LeetCode] 70. Climbing Stairs
[勇者闯LeetCode] 70. Climbing Stairs Description You are climbing a stair case. It takes n steps to rea ...
- [勇者闯LeetCode] 112. Path Sum
[勇者闯LeetCode] 112. Path Sum Description Given a binary tree and a sum, determine if the tree has a r ...
最新文章
- Codeforces 1408 D. Searchlights(优化DP、思维)
- 苹果6屏幕多大_相较前段新鲜感满满,谈谈苹果12这几天的实际感受
- Shell中的Wget 的用法
- IDEA工具创建项目并提交码云和一些基本使用
- github密码格式_如何使用GitHub构建一个简单的网页 (不用框架版本)
- 二叉搜索树简介和部分题目
- 【学习笔记】系统观核心管理理论
- OpenGL ES之3D渲染旋转的贴图立方体
- 在 SELECT 查询中使用透视
- Eclipse 快捷键 查看方法在那里被调用~
- HDU 5834 Magic boy Bi Luo with his excited tree 树形DP
- googel的扩展插件导出与导入
- tomcat的目录结构
- JAVA笔记20-容器之四Map接口、自动打包、泛型(重要)
- 药物临床试验数据递交PMDA的规定
- 玉米社:短视频运营主要做哪些工作?
- css定位-css新增选择器(内减,属性,伪类,2d变换,过渡)
- python报错: arry[i] = t IndexError: list assignment index out of range
- Google Earth Engine(GEE)——
- 奇虎360 2013校园招聘笔试题