leetcode_验证回文字符串
还是双指针题目
1 class Solution { 2 3 public boolean validPalindrome(String s) { 4 char ch[] =s.toCharArray(); 5 int i=0; int j = ch.length-1; 6 while(i<j) { 7 if(ch[i]==ch[j]) { 8 i++;j--; 9 }else { 10 return isEqual(ch, i+1, j)||isEqual(ch, i, j-1); 11 } 12 } 13 return true; 14 15 } 16 17 public boolean isEqual(char ch[],int i,int j){ 18 while(i<j) { 19 if(ch[i]==ch[j]) { 20 i++;j--; 21 }else { 22 return false; 23 } 24 25 } 26 return true; 27 } 28 29 }

浙公网安备 33010602011771号