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
原文:http://www.cnblogs.com/shuashuashua/p/7542567.html