We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2d339cd commit 97911b7Copy full SHA for 97911b7
valid-palindrome/gitsunmin.ts
@@ -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