Skip to content

Commit 9dc2b08

Browse files
committed
solve valid palindrom [sliding window + chatCodeAt]
1 parent bac506f commit 9dc2b08

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

valid-palindrome/JangAyeon.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
var isPalindrome = function (s) {
6+
const sLowered = [...s.toLowerCase().replace(" ", "")];
7+
const isAlpha = (item) => item.charCodeAt() >= 97 && item.charCodeAt() <= 122;
8+
const isNumber = (item) => item.charCodeAt() >= 48 && item.charCodeAt() <= 57;
9+
const str = sLowered.filter((c) => isAlpha(c) || isNumber(c));
10+
const N = str.length;
11+
let [start, end] = [0, N - 1];
12+
while (start <= end) {
13+
if (str[start] != str[end]) {
14+
return false;
15+
}
16+
start++;
17+
end--;
18+
}
19+
return true;
20+
};

0 commit comments

Comments
 (0)