Time Complexity O(n)
Space Complexity O(n)
class Solution {
public boolean isPalindrome(String s) {
s = s.replaceAll("[^a-zA-Z0-9]", "").toLowerCase();
int left = 0;
int right = s.length() - 1;
while(left < right) {
if (s.charAt(left) != s.charAt(right))
return false;
left++;
right--;
}
return true;
}
}
Top comments (0)