Link to the problem here.
class Solution {
public boolean isPalindrome(String s) {
s = s.toLowerCase();
int left = 0;
int right = s.length() - 1;
while (left < right){
char leftLetter = s.charAt(left);
char rightLetter = s.charAt(right);
if (!Character.isLetterOrDigit(leftLetter)){
left++;
}
else
if (!Character.isLetterOrDigit(rightLetter)){
right--;
continue;
}
else
{ if (leftLetter != rightLetter)
return false;
else{
left++;
right--;
}}
}
return true;
}
}
Time Complexity: , Space Complexity:
Explanation: To solve this problem i use two indexes, what start from begin and end of string. first think first check if any of characters with index is a space, if yes, we skip tis index, if not we check are a symbols
the same. If yes , we just bring next indexes, if not, we return false
.