We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5dbcda1 commit 4f956d6Copy full SHA for 4f956d6
valid-palindrome/jun0811.js
@@ -0,0 +1,32 @@
1
+var isPalindrome = function (s) {
2
+ let left = 0;
3
+ let right = s.length - 1;
4
+
5
+ while (left < right) {
6
+ while (left < right && !isAlphaNumeric(s[left])) {
7
+ left++;
8
+ }
9
10
+ while (left < right && !isAlphaNumeric(s[right])) {
11
+ right--;
12
13
14
+ if (s[left].toLowerCase() !== s[right].toLowerCase()) {
15
+ return false;
16
17
18
19
20
21
22
+ return true;
23
+};
24
25
+function isAlphaNumeric(char) {
26
+ const code = char.charCodeAt(0);
27
+ return (
28
+ (code >= 48 && code <= 57) || // 0-9
29
+ (code >= 65 && code <= 90) || // A-Z
30
+ (code >= 97 && code <= 122)
31
+ ); // a-z
32
+}
0 commit comments