--- palindromic double pointer string

Times character marks skewer

680. Valid Palindrome II (Easy)

Input: "abca"
Output: True
Explanation: You could delete the character 'c'.

Subject description:

  You can delete a character, can be configured to determine whether the palindrome string.

Code:

public boolean validPalindrome(String s){
    int i==-1;
    int j=s.length();
    while(++i<--j){
        if(s.charAt(i)!=s.charAt(j)){
            return isPalindrome(s,i,j-1)||isPalindrome(s,i+1,j); //删除一个字符后,判断剩下的是否为回文
        }
    }
    private boolean isPalindrome(String s ,int i,int j){
        while(i<j){
            if(s.charAt(i++)!=s.charAt(j--))
                return false;
        }
        return true;
    }
}

Guess you like

Origin www.cnblogs.com/yjxyy/p/11104408.html