Open pwstrick opened 4 years ago
680. 验证回文字符串 Ⅱ
/** * @param {string} s * @return {boolean} */ var validPalindrome = function(s) { let l = 0, r = s.length - 1; while(l < r) { if(s[l] != s[r]) { return isPalindrome(s, l+1, r) || isPalindrome(s, l, r-1); } l++; r--; } return true; }; function isPalindrome(s, l, r) { while(l < r) { if(s[l] != s[r]) return false; l++; r--; } return true; }
680. 验证回文字符串 Ⅱ