Skip to content

Commit 1beb0aa

Browse files
committed
valid-palindrome
1 parent 32633cc commit 1beb0aa

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

valid-palindrome/sooooo-an.ts

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

0 commit comments

Comments
 (0)