We resolving power button brush topic 680 topic, this paper test II palindrome string ontology antithesis: in the original “test I palindrome string”, subject need to give a chance to delete the elements of a palindrome, and move on after delete the judgment, about at the end of the pointer is equal when the pointer on the right side of the pointer to the right or left, palindrome verify correct.

Var validPalindrome = function(s) {// Let left = 0,right = s.length-1 While (left<right){if(s[left]! == s[right]){// We have a chance to skip the element, so we create a function below to continue the verification after the jump. If either of the two methods is true, it is still a palindrome string. const res = oneChance(left+1,right) || oneChance(left,right-1) return res } left++ right-- } If left=right or left>right does not return false, the palindrome string is valid. Return true gives an opportunity to skip the validation error. function oneChance(left,right){ while(left<right){ if(s[left] ! == s[right]){ return false } left++ right-- } return true } };Copy the code