Skip to content

Commit a1a9fd8

Browse files
committed
Valid Palindrome Solution
1 parent 35ded94 commit a1a9fd8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

valid-palindrome/naringst.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
6+
/**
7+
* Runtime: 66ms, Memory: 54.75MB
8+
* Time complexity: O(s.length)
9+
* Space complexity: O(s.length)
10+
*
11+
*/
12+
13+
var isPalindrome = function (s) {
14+
let trimmed = s.toLowerCase();
15+
let answer = [];
16+
let checkAlphabet = /[a-zA-Z]/;
17+
let checkNum = /[0-9]/;
18+
19+
for (let alpha of trimmed) {
20+
if (checkAlphabet.test(alpha) || checkNum.test(alpha)) {
21+
answer.push(alpha);
22+
}
23+
}
24+
25+
if (answer.join("") === answer.reverse().join("")) {
26+
return true;
27+
}
28+
return false;
29+
};

0 commit comments

Comments
 (0)