We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给定一个非空字符串 s,最多删除一个字符。判断是否能成为回文字符串。
示例 1:
输入: s = "aba" 输出: true
示例 2:
输入: s = "abca" 输出: true 解释: 你可以删除c字符。
示例 3:
输入: s = "abc" 输出: false
提示:
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/valid-palindrome-ii 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
const validPalindrome = (s, lev = 0) => { let left = 0, right = s.length - 1 while (left < right) { if (s[left] !== s[right]) { if (lev >= 1) return false const leftStr = s.slice(left, right) const rightStr = s.slice(left + 1, right + 1) return validPalindrome(leftStr, lev + 1) || validPalindrome(rightStr, lev + 1) } left++ right-- } return true }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
给定一个非空字符串 s,最多删除一个字符。判断是否能成为回文字符串。
示例 1:
示例 2:
示例 3:
提示:
The text was updated successfully, but these errors were encountered: