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 a4869e0 commit c62e032Copy full SHA for c62e032
valid-palindrome/yhkee0404.ts
@@ -0,0 +1,19 @@
1
+function isPalindrome(s: string): boolean {
2
+ const isAlpha = x => x.toLowerCase() >= 'a' && x.toLowerCase() <= 'z';
3
+ const isNumeric = x => x >= '0' && x <= '9';
4
+ const isAlphanumeric = x => isAlpha(x) || isNumeric(x);
5
+ let i = 0, j = s.length - 1;
6
+ while (i < j) {
7
+ while (i !== j && ! isAlphanumeric(s[i])) {
8
+ i++;
9
+ }
10
+ while (i !== j && ! isAlphanumeric(s[j])) {
11
+ j--;
12
13
+ if (s[i].toLowerCase() !== s[j].toLowerCase()) {
14
+ return false;
15
16
+ i++, j--;
17
18
+ return true;
19
+};
0 commit comments