You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
497 B
TypeScript
31 lines
497 B
TypeScript
function isLetter(c: string) {
|
|
if (/\d/.test(c)) return true;
|
|
return c.toLowerCase() != c.toUpperCase();
|
|
|
|
}
|
|
|
|
export function isPalindrome(s: string): boolean {
|
|
let L = 0;
|
|
let R = s.length - 1;
|
|
|
|
while (L <= R) {
|
|
let lChar = s[L].toLowerCase();
|
|
let rChar = s[R].toLowerCase();
|
|
|
|
if (!isLetter(lChar)) {
|
|
L++;
|
|
continue;
|
|
}
|
|
if (!isLetter(rChar)) {
|
|
R--;
|
|
continue;
|
|
}
|
|
|
|
if (lChar !== rChar) return false;
|
|
L++;
|
|
R--;
|
|
}
|
|
|
|
return true;
|
|
};
|