Skip to content

Commit

Permalink
[Leetcode - Easy] Valid Palindrome (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
BangDori authored Dec 21, 2024
1 parent 0a2e50f commit f0bb8cc
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions bangdori/Valid Palindrome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @param {string} s
* @return {boolean}
*/
var isPalindrome = function (s) {
const removedNonAlphanemuricString = [...s.toLowerCase()].filter(
(alpha) => isLowerAlphabet(alpha) || isNumeric(alpha)
);

return (
removedNonAlphanemuricString.join("") ===
removedNonAlphanemuricString.reverse().join("")
);
};

function isLowerAlphabet(character) {
return character >= "a" && character <= "z";
}

function isNumeric(character) {
return character >= "0" && character <= "9";
}

0 comments on commit f0bb8cc

Please sign in to comment.