Skip to content

Commit 97911b7

Browse files
committed
Add week 4 solutions: valid-palindrome
1 parent 2d339cd commit 97911b7

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

valid-palindrome/gitsunmin.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* https://leetcode.com/problems/valid-palindrome
3+
* time complexity : O(n)
4+
* space complexity : O(n)
5+
*/
6+
7+
const clean = (s: string): string => s.toLowerCase().replace(/[^a-z0-9]/g, "");
8+
9+
const reverse = (s: string): string => s.split("").reverse().join("");
10+
11+
function isPalindrome(s: string): boolean {
12+
const cleaned = clean(s);
13+
return cleaned === reverse(cleaned);
14+
};

0 commit comments

Comments
 (0)