bool isPalindrome(string s) {
string cleaned;
for (char c : s) if (isalnum((unsigned char)c)) cleaned += tolower((unsigned char)c);
string reversed(cleaned.rbegin(), cleaned.rend());
return cleaned == reversed;
}
public boolean isPalindrome(String s) {
String cleaned = s.toLowerCase().replaceAll("[^a-z0-9]", "");
String reversed = new StringBuilder(cleaned).reverse().toString();
return cleaned.equals(reversed);
}
def is_palindrome(s: str) -> bool:
cleaned = ''.join(c.lower() for c in s if c.isalnum())
reversed_s = cleaned[::-1]
return cleaned == reversed_s
function isPalindrome(s: string): boolean {
const cleaned = s.toLowerCase().replace(/[^a-z0-9]/g, '');
const reversed = cleaned.split('').reverse().join('');
return cleaned === reversed;
}
bool isPalindrome(string s) {
string cleaned;
for (char c : s) if (isalnum((unsigned char)c)) cleaned += tolower((unsigned char)c);
int left = 0;
int right = (int)cleaned.size() - 1;
while (left < right) {
if (cleaned[left] != cleaned[right]) return false;
left++;
right--;
}
return true;
}
public boolean isPalindrome(String s) {
String cleaned = s.toLowerCase().replaceAll("[^a-z0-9]", "");
int left = 0;
int right = cleaned.length() - 1;
while (left < right) {
if (cleaned.charAt(left) != cleaned.charAt(right)) return false;
left++;
right--;
}
return true;
}
def is_palindrome(s: str) -> bool:
cleaned = ''.join(c.lower() for c in s if c.isalnum())
left = 0
right = len(cleaned) - 1
while left < right:
if cleaned[left] != cleaned[right]: return False
left += 1
right -= 1
return True
function isPalindrome(s: string): boolean {
const cleaned = s.toLowerCase().replace(/[^a-z0-9]/g, '');
let left = 0;
let right = cleaned.length - 1;
while (left < right) {
if (cleaned[left] !== cleaned[right]) return false;
left++;
right--;
}
return true;
}
bool isPalindrome(string s) {
int left = 0;
int right = (int)s.size() - 1;
auto isAlnum = [](char c) { return isalnum((unsigned char)c) != 0; };
while (left < right) {
while (left < right && !isAlnum(s[left])) left++;
while (left < right && !isAlnum(s[right])) right--;
if (tolower((unsigned char)s[left]) != tolower((unsigned char)s[right])) return false;
left++;
right--;
}
return true;
}
public boolean isPalindrome(String s) {
int left = 0;
int right = s.length() - 1;
java.util.function.IntPredicate isAlnum = Character::isLetterOrDigit;
while (left < right) {
while (left < right && !isAlnum.test(s.charAt(left))) left++;
while (left < right && !isAlnum.test(s.charAt(right))) right--;
if (Character.toLowerCase(s.charAt(left)) != Character.toLowerCase(s.charAt(right))) return false;
left++;
right--;
}
return true;
}
def is_palindrome(s: str) -> bool:
left = 0
right = len(s) - 1
while left < right:
while left < right and not s[left].isalnum(): left += 1
while left < right and not s[right].isalnum(): right -= 1
if s[left].lower() != s[right].lower(): return False
left += 1
right -= 1
return True
function isPalindrome(s: string): boolean {
let left = 0;
let right = s.length - 1;
const isAlnum = (c: string) => /[a-z0-9]/i.test(c);
while (left < right) {
while (left < right && !isAlnum(s[left])) left++;
while (left < right && !isAlnum(s[right])) right--;
if (s[left].toLowerCase() !== s[right].toLowerCase()) return false;
left++;
right--;
}
return true;
}
static inline bool isAlnumCode(int c) { return (c >= 48 && c <= 57) || ((c | 32) >= 97 && (c | 32) <= 122); }
bool isPalindrome(const string& s) {
int left = 0;
int right = (int)s.size() - 1;
while (left < right) {
int a = (unsigned char)s[left];
int b = (unsigned char)s[right];
if (!isAlnumCode(a)) { left++; continue; }
if (!isAlnumCode(b)) { right--; continue; }
if ((a | 32) != (b | 32)) return false;
left++;
right--;
}
return true;
}
private static boolean isAlnumCode(int c) { return (c >= 48 && c <= 57) || ((c | 32) >= 97 && (c | 32) <= 122); }
public boolean isPalindrome(String s) {
int left = 0;
int right = s.length() - 1;
while (left < right) {
int a = s.charAt(left);
int b = s.charAt(right);
if (!isAlnumCode(a)) { left++; continue; }
if (!isAlnumCode(b)) { right--; continue; }
if ((a | 32) != (b | 32)) return false;
left++;
right--;
}
return true;
}
def _is_alnum_code(c: int) -> bool: return 48 <= c <= 57 or 97 <= (c | 32) <= 122
def is_palindrome(s: str) -> bool:
left = 0
right = len(s) - 1
while left < right:
a = ord(s[left])
b = ord(s[right])
if not _is_alnum_code(a):
left += 1
continue
if not _is_alnum_code(b):
right -= 1
continue
if (a | 32) != (b | 32): return False
left += 1
right -= 1
return True
const isAlnumCode = (c: number) => (c >= 48 && c <= 57) || ((c | 32) >= 97 && (c | 32) <= 122);
function isPalindrome(s: string): boolean {
let left = 0;
let right = s.length - 1;
while (left < right) {
const a = s.charCodeAt(left);
const b = s.charCodeAt(right);
if (!isAlnumCode(a)) { left++; continue; }
if (!isAlnumCode(b)) { right--; continue; }
if ((a | 32) !== (b | 32)) return false;
left++;
right--;
}
return true;
}