Skip to content

Commit f863f03

Browse files
committed
valid palindrome solution
1 parent f69468c commit f863f03

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

valid-palindrome/yoonthecoder.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var isPalindrome = function (s) {
2+
// remove any special characters and space from the string
3+
const formattedString = s.toLowerCase().replace(/[^a-zA-Z0-9]/g, '');
4+
// use split() method to separate each charaters and put them in an array - reverse it - concatenate
5+
const reversedString = formattedString.split('').reverse().join('');
6+
7+
return reversedString === formattedString;
8+
};
9+
10+
// time complexity: O(n)
11+
// space complexity: O(n)

0 commit comments

Comments
 (0)