题目
输入一个字符串,判断该字符串中除去空格之后的字符串是否为回文字符串。
要求:不可使用 Java 已实现的方法替换空格,不可消耗额外的空间
代码实现
- 此处为判断方法的实现
public static boolean isPla(String str) {
if(str.length()==0 || str.length() == 1) {
reurn true;
}
int i = 0, j = str.length() - 1;
while(i < j) {
while(str.charAt(i) == ' ')
i++;
while(str.charAt(j) == ' ')
j++;
if(str.charAt(i) != str.charAt(j)) {
return false;
}
}
return true;
}