We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8276bc6 commit 0ea6ce8Copy full SHA for 0ea6ce8
1 file changed
valid-palindrome/junzero741.ts
@@ -0,0 +1,29 @@
1
+// TC: O(n)
2
+// SC: O(1)
3
+function isPalindrome(s: string): boolean {
4
+
5
+ let L = 0;
6
+ let R = s.length-1;
7
8
+ while(R > 0 && L < s.length - 1 && L <= R) {
9
+ if(!isAlphanumeric(s[L])) {
10
+ L++;
11
+ continue;
12
+ }
13
+ if(!isAlphanumeric(s[R])) {
14
+ R--;
15
16
17
+ if(s[L].toLowerCase() !== s[R].toLowerCase()) {
18
+ return false;
19
20
21
22
23
24
+ return true;
25
+};
26
27
+function isAlphanumeric(str: string): boolean {
28
+ return /^[a-zA-Z0-9]+$/.test(str);
29
+}
0 commit comments