Skip to content

Commit 4e1d2b0

Browse files
committed
add: #220 Valid Palindrome
1 parent aa151cd commit 4e1d2b0

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

valid-palindrome/sukyoungshin.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const alphaNumSet = new Set([..."abcdefghijklmnopqrstuvwxyz0123456789"]);
2+
3+
function isPalindrome(s: string): boolean {
4+
let normalized = "";
5+
6+
for (const characters of s) {
7+
const lower = characters.toLowerCase();
8+
if (alphaNumSet.has(lower)) {
9+
normalized += lower;
10+
}
11+
}
12+
13+
let left = 0;
14+
let right = normalized.length - 1;
15+
while (left < right) {
16+
if (normalized[left] !== normalized[right]) {
17+
return false;
18+
}
19+
left++;
20+
right--;
21+
}
22+
23+
return true;
24+
}

0 commit comments

Comments
 (0)