Skip to content

Commit 11e43f8

Browse files
committed
feat: 220.Valid Palindrome
1 parent c9407bb commit 11e43f8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

valid-palindrome/gwbaik9717.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Time complexity: O(n)
2+
// Space complexity: O(n)
3+
4+
/**
5+
* @param {string} s
6+
* @return {boolean}
7+
*/
8+
var isPalindrome = function (s) {
9+
const normalize = (s) => {
10+
return s.toLowerCase().replace(/[^a-z0-9]/g, "");
11+
};
12+
13+
const normalized = normalize(s);
14+
const reversed = normalized.split("").reverse().join("");
15+
16+
return normalized === reversed;
17+
};

0 commit comments

Comments
 (0)