Skip to content

Commit 9a3c3f3

Browse files
committed
valid-palindrome
1 parent eae9bb0 commit 9a3c3f3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

valid-palindrome/taewanseoul.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* 125. Valid Palindrome
3+
* A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all
4+
* non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters
5+
* and numbers.
6+
* Given a string s, return true if it is a palindrome, or false otherwise.
7+
* https://leetcode.com/problems/valid-palindrome/description/
8+
*/
9+
function isPalindrome(s: string): boolean {
10+
const chars = s.replace(/[^a-z0-9]/gi, "").toLowerCase();
11+
12+
return chars === [...chars].reverse().join("");
13+
}
14+
15+
// O(n) time
16+
// O(n) space

0 commit comments

Comments
 (0)