直接双指针
import java.util.*;
public class Solution {
public boolean judge (String str) {
// write code here
int n = str.length();
if(n == 0 || n == 1)
return true;
int left = 0, right = n-1;
while(left < right){
if(str.charAt(left) != str.charAt(right))
return false;
left++;
right--;
}
return true;
}
}

京公网安备 11010502036488号