Skip to content

Commit 7c8ee20

Browse files
committed
valid palindrome
1 parent d4c4209 commit 7c8ee20

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

valid-palindrome/sounmind.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function isPalindrome(s: string): boolean {
2+
const filteredString = s.replace(/[^a-zA-Z0-9]/g, "").toUpperCase();
3+
4+
let [left, right] = [0, filteredString.length - 1];
5+
6+
while (left <= right) {
7+
if (filteredString[left] !== filteredString[right]) {
8+
return false;
9+
}
10+
11+
left += 1;
12+
right -= 1;
13+
}
14+
15+
return true;
16+
}

0 commit comments

Comments
 (0)