public boolean isPalindrome(String s) {
// Write your code here
if(s.length() == 0 || s == null)
return true;
s = s.toLowerCase();
s = s.trim();
int i = 0;
int j = s.length() - 1;
while(i <= j) {
while(i <= j && !((s.charAt(i) <= 'z' && s.charAt(i) >= 'a') || (s.charAt(i) >= '0' && s.charAt(i) <= '9')))
i++;
while(i <= j && !((s.charAt(j) <= 'z' && s.charAt(j) >= 'a') || (s.charAt(j) >= '0' && s.charAt(j) <= '9')))
j--;
if(i <= j && s.charAt(i) != s.charAt(j))
return false;
i++;
j--;
}
return true;
}
Leave A Comment