Skip to content

Commit db404ba

Browse files
committed
220. Valid Palindrome
1 parent 04e072c commit db404ba

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

valid-palindrome/choidabom.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Runtime: 7ms, Memory: 55.02MB
3+
*
4+
* Time Complexity: O(n)
5+
* Space Complexity: O(n)
6+
*/
7+
8+
/**
9+
* @param {string} s
10+
* @return {boolean}
11+
*/
12+
function isPalindrome(s) {
13+
const alphanumeric = getAlphanumeric(s)
14+
return alphanumeric === alphanumeric.split("").reverse().join("")
15+
}
16+
17+
function getAlphanumeric(string) {
18+
const number = /[0-9]/
19+
const alphabet = /[a-zA-Z]/
20+
let alphanumeric = []
21+
22+
for (const str of string) {
23+
if (number.test(str) || alphabet.test(str)) {
24+
alphanumeric.push(str)
25+
}
26+
}
27+
return alphanumeric.join("").toLowerCase()
28+
}

0 commit comments

Comments
 (0)