Skip to content

Commit 47d32ee

Browse files
committed
Time: 2 ms (92.6%), Space: 55.2 MB (97.28%) - LeetHub
1 parent 46ed677 commit 47d32ee

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
var isPalindrome = function(s) {
6+
7+
const isAlphaNumeric = (char) => {
8+
const charCode = char.charCodeAt(0)
9+
return (
10+
(charCode <= 90 && charCode >= 65) ||
11+
(charCode <= 57 && charCode >= 48)
12+
)
13+
}
14+
15+
const sLower = s.toUpperCase()
16+
var left = 0
17+
var right = sLower.length-1
18+
19+
while(left < right){
20+
const leftChar = sLower.charAt(left)
21+
const rightChar = sLower.charAt(right)
22+
23+
if(!isAlphaNumeric(leftChar)){
24+
left++
25+
continue
26+
}
27+
if(!isAlphaNumeric(rightChar)){
28+
right--
29+
continue
30+
}
31+
32+
if(leftChar != rightChar) return false
33+
34+
left++
35+
right--
36+
}
37+
38+
return true
39+
};

0 commit comments

Comments
 (0)