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; } }
时间: 2024-10-20 23:33:13