Leetcode检测时是对的但是一执行就错,我放在myeclipse里面也是对的
问题描述:
答
class Solution {
public boolean isPalindrome(String s) {
s = s.toLowerCase();
String p = "";
for (int i = 0; i < s.length(); i++) {
if ((s.charAt(i) >= 'a' && s.charAt(i) <= 'z') || (s.charAt(i) >= '0' && s.charAt(i) <= '9')) {
p = p + s.substring(i, i + 1);
}
}
for (int i = 0; i < p.length()/2; i++) {
if (p.charAt(i) != p.charAt(p.length() - i - 1)) {
return false;
}
}
return true;
}
}
答
采纳,后 我教你
答
只考虑字母和数字字符,忘考虑数字字符了