LeetCode 680: Valid Palindromes

Posted keepshuatishuati

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode 680: Valid Palindromes相关的知识,希望对你有一定的参考价值。

class Solution {
    public boolean validPalindrome(String s) {
        int start = 0, end = s.length() - 1;
        boolean found = false;
        while (start < end) {
            if (s.charAt(start) != s.charAt(end)) {
                return isPal(s, start, end - 1) || isPal(s, start + 1, end);
            }
            start++;
            end--;
        }
        return true;
    }
    
    private boolean isPal(String s, int start, int end) {
        while (start < end) {
            if (s.charAt(start) != s.charAt(end)) {
                return false;
            }
            start++;
            end--;
        }
        return true;
    }
}

 

以上是关于LeetCode 680: Valid Palindromes的主要内容,如果未能解决你的问题,请参考以下文章

[leetcode-680-Valid Palindrome II]

Leetcode 680: Valid Palindrome II

leetcode-680-Valid Palindrome II

Python 解LeetCode:680. Valid Palindrome II

LeetCode 680. 验证回文字符串 Ⅱ [Valid Palindrome II (Easy)]

LeetCode 680. 验证回文字符串 Ⅱ [Valid Palindrome II (Easy)]