leetcode(js)-每日一练之 验证回文串Ⅱ 题库编号680
2020-06-04 06:45
169 查看
leetcode(js)-每日一练之 验证回文串Ⅱ
主要思路:
- 首先跟题库编号125 验证回文字符串的思路相同
- 在left(++)和right(–)指针行进过程中,若比较后发现不同,给一次机会,把left++与right 比较 或 right-- 与left 比较,如果有一个返回true,则次字符串珍惜了这次机会,是一个回文字符串,否则仍不是回文字符串
- 为什么不left-- right++呢 ,因为在每次比较 都要确定左右两边的字符数相同,才符合题意
var validPalindrome = function(s) { function isHui(left, right) { while (left < right) { if (s[left] != s[right]) { return false } left++; right--; } return true; } let left = 0; let right = s.length - 1; while (left < right) { if (s[left] != s[right]) { return isHui(left + 1, right) || isHui(left,right - 1); } left++; right--; } return true; };
相关文章推荐
- leetcode(js)-每日一练之 存在重复元素 题库编号217 219
- leetcode(js)-每日一练之 打家劫舍 题库编号198
- leetcode(js)-每日一练之 寻找旋转排序数组中的最小值 题库编号153
- leetcode(js)-每日一练之 乘积最大子数组 题库编号152
- leetcode(js)-每日一练之 加油站 题库编号134
- LeetCode每日一题--验证回文串
- Leetcode题库 - 验证回文串(java语言版)
- LeetCode每日一题———409. 最长回文串
- LeetCode解析---125.验证回文串
- 一个交易编号的的验证的Js的编写
- LeetCode-680 验证回文字符串Ⅱ
- LeetCode 125.验证回文串
- [leetcode]验证回文串[javascript]
- LeetCode-125. 验证回文串(C语言)
- leetcode-680-验证回文字符串
- LeetCode-125.验证回文串(相关话题:字符串)
- 验证回文串--leetcode第125题
- LeetCode125-验证回文串
- Leetcode:125.验证回文串
- leetcode 125 验证回文串