Skip to content

Commit c6f7608

Browse files
committed
valid palindrome solution
1 parent 41f23d7 commit c6f7608

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

valid-palindrome/froggy1014.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
6+
var isPalindrome = function (s) {
7+
const str = s.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
8+
let left = 0;
9+
let right = str.length - 1;
10+
11+
while (left < right) {
12+
if (str[left] !== str[right]) return false;
13+
left++;
14+
right--;
15+
}
16+
17+
return true;
18+
};
19+
20+
console.log(isPalindrome("A man, a plan, a canal: Panama"));
21+
console.log(isPalindrome("race a car"));
22+
console.log(isPalindrome(" "));

0 commit comments

Comments
 (0)