Skip to content

Commit c62e032

Browse files
authored
valid palindrome solution
1 parent a4869e0 commit c62e032

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

valid-palindrome/yhkee0404.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function isPalindrome(s: string): boolean {
2+
const isAlpha = x => x.toLowerCase() >= 'a' && x.toLowerCase() <= 'z';
3+
const isNumeric = x => x >= '0' && x <= '9';
4+
const isAlphanumeric = x => isAlpha(x) || isNumeric(x);
5+
let i = 0, j = s.length - 1;
6+
while (i < j) {
7+
while (i !== j && ! isAlphanumeric(s[i])) {
8+
i++;
9+
}
10+
while (i !== j && ! isAlphanumeric(s[j])) {
11+
j--;
12+
}
13+
if (s[i].toLowerCase() !== s[j].toLowerCase()) {
14+
return false;
15+
}
16+
i++, j--;
17+
}
18+
return true;
19+
};

0 commit comments

Comments
 (0)