[LeetCode] 680. Valid Palindrome II_Easy tag: Two Pointers
Given a non-empty string s
, you may delete at most one character. Judge whether you can make it a palindrome.
Example 1:
Input: "aba"
Output: True
Example 2:
Input: "abca"
Output: True
Explanation: You could delete the character 'c'.
Note:
- The string will only contain lowercase characters a-z. The maximum length of the string is 50000.
题目思路就是正常的用two pointers去遍历s, 然后如果有不一样的, 要么把l + = 1, 要么把r -= 1 , 然后如果这两个中有一个是palindrome, 那么就符合.
Code:
class Solution:
def palindrome2(self, s): # len(s) >= 1
l, r = 0, len(s)-1
def helper(l, r, s):
while l < r:
if s[l] == s[r]:
l += 1
r -= 1
else:
return False
return True
while l <r:
if s[l] == s[r]:
l += 1
r -= 1
else:
return helper(l+1, r, s) or helper(l, r-1, s)
return True
[LeetCode] 680. Valid Palindrome II_Easy tag: Two Pointers的更多相关文章
- [LeetCode] 680. Valid Palindrome II 验证回文字符串 II
Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...
- [leetcode]680. Valid Palindrome II有效回文II(可至多删一原字符)
Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...
- LeetCode 680. Valid Palindrome II (验证回文字符串 Ⅱ)
Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...
- LeetCode 680. Valid Palindrome II(双指针)
题意:给定一个字符串,可以最多去掉一个字符,判断是否可以使该字符串成为一个回文串. 分析:head和tail双指针分别指向字符串首尾,如果s[head] != s[tail],则要么去掉s[head] ...
- 680. Valid Palindrome II【easy】
680. Valid Palindrome II[easy] Given a non-empty string s, you may delete at most one character. Jud ...
- 【Leetcode_easy】680. Valid Palindrome II
problem 680. Valid Palindrome II solution: 不理解判断函数中的节点的问题... class Solution { public: bool validPali ...
- [Leetcode][JAVA] Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- LeetCode 125. Valid Palindrome
这个题目只要注意大小写问题即可解决,而且我们只关注的是字母和数值 Given a string, determine if it is a palindrome, considering only a ...
- [leetcode] 1. Valid Palindrome
leetcode的第一题,回文数判断. 原题如下: For example, "A man, a plan, a canal: Panama" is a palindrome. & ...
随机推荐
- jquery.peity.js简介
jQuery简单图表peity.js <html xmlns="http://www.w3.org/1999/xhtml"> <head> <titl ...
- Android自定义组件——四个方向滑动的菜单实现
今天无意中实现了一个四个方向滑动的菜单,感觉挺好玩,滑动起来很顺手,既然已经做出来了就贴出来让大家也玩弄一下. 一.效果演示 (说明:目前没有安装Android模拟器,制作的动态图片太卡了,就贴一下静 ...
- 小程序判断是否授权源码 auth.js
一.auth.js const configGlobal = require('../config/config_global.js'); var util = require('function.j ...
- Word 2010 插入其他文件的方法
1. 2.
- isolinux.cfg 文件是干什么的
1. 首先光盘镜像也就是iso文件采用的是“ISO 9660 ”文件系统 . cd上的文件都存在这个简单的iso文件系统里,linux可以用mount -o loop 直接把*.iso文件mou ...
- 【咸鱼教程】Wing动画编辑器创建精美(一般-_-)开场动画
游戏中会用着一些简单的动画,公司一般使用的dragonbones制作,导出二进制格式或者MC来使用.感觉一些简单动画直接使用动画编辑器更加简便些. 引擎版本:5.0.14wing版本:4.1.0 一 ...
- Unity3D笔记 NUGUI 一
NGUI是严格遵循KISS原则(KISS原则,keep it simple and stupid ,简单的理解这句话就是,要把一个系统做的连白痴都会用.这就是用户体验的高层境界了,好听的说法也是有的, ...
- Windows Server 2008 R2之六活动目录域服务的卸载
活动目录域服务的卸载是将DC降级为独立服务器或成员服务器的过程. 在删除活动目录之前,为了防止操作失败操作系统故障,须对系统进行备份.同时,我们还必须对待删除的域控制器进行如下检查 1.是否有操作主控 ...
- 8.30前端jQuery和数据结构知识
2018-8-30 16:37:17 单链表的demo 从俺弟家回来了! 发现,还是要努力学习是很重要的!!努力学习新的感兴趣的东西!! 多读书还是很重要的!!! 越努力,越幸运! # coding: ...
- 公司HBase基准性能测试之结果篇
上一篇文章<公司HBase基准性能测试之准备篇>中详细介绍了本次性能测试的基本准备情况,包括测试集群架构.单台机器软硬件配置.测试工具以及测试方法等,在此基础上本篇文章主要介绍HBase在 ...