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
/* 输入: "aba" 输出: True 输入: "abca" 输出: True 注意: 字符串只包含从 a-z 的小写字母。字符串的最大长度是50000。 */
每日一题会在下午四点在交流群集中讨论,五点小程序中更新答案 欢迎大家在下方发表自己的优质见解 二维码加载失败可点击 小程序二维码
每日一题会在下午四点在交流群集中讨论,五点小程序中更新答案 欢迎大家在下方发表自己的优质见解
The text was updated successfully, but these errors were encountered:
function isCanbePalindrome(s) { let l = 0, r = s.length - 1 while(l < r) { if (s[l] !== s[r]) { // 一旦遇到不同的,要么取左舍右,要么取右舍左 return isPalindrome(l, r - 1) || isPalindrome(l + 1, r) } l++ r-- } return true function isPalindrome(l, r) { while(l < r) { if (s[l] !== s[r]) return false l++ r-- } return true } }
Sorry, something went wrong.
function isCanbePalindrome(s) { function isPalindromeR(l , r, valid) { while(l < r) { if (s[l] !== s[r]) { if (!valid) return false // 一旦 valid 为 false, 则说明是第二次不同 return isPalindromeR(l, r - 1, false) || isPalindromeR(l + 1, r, false) } l++ r-- } return true } return isPalindromeR(0, s.length - 1, true) }
const main = (s) => { let left = 0 let right = s.length - 1 let maxDelete = 1 while (left <= right) { if (s[left] === s[right]) { left++ right-- } else { if (maxDelete) { if (s[left + 1] === s[right]) { left = left + 2 right-- } else if (s[left] === s[right - 1]) { left++ right = right - 2 } maxDelete-- } else return false } } return true }
No branches or pull requests
扫描下方二维码,收藏关注,及时获取答案以及详细解析,同时可解锁800+道前端面试题。
The text was updated successfully, but these errors were encountered: