public class Solution {
public boolean isPalindrome(String s) {
s = s.trim().replaceAll("\\W", "").toLowerCase();
for(int i = 0; i < (s.length() + 1) / 2; i++) {
if(s.charAt(i) != s.charAt(s.length() - 1 - i)) {
return false;
}
}
return true;
}
}
Time: O(n)
Space: O(1)