Skip to content

Commit 4b54a7d

Browse files
authored
feat: add typescript solution to lc problem: No.0125.Valid Palindrome (doocs#431)
1 parent c0bb42a commit 4b54a7d

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

solution/0100-0199/0125.Valid Palindrome/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,29 @@ private:
103103
};
104104
```
105105
106+
### **tTypeScript**
107+
108+
```ts
109+
function isPalindrome(s: string): boolean {
110+
let left: number = 0, right: number = s.length - 1;
111+
while (left < right) {
112+
let char1: string = s.charAt(left);
113+
let char2: string = s.charAt(right);
114+
if (!(/[a-zA-Z0-9]/).test(char1)) {
115+
++left;
116+
} else if (!(/[a-zA-Z0-9]/).test(char2)) {
117+
--right;
118+
} else if (char1.toLocaleLowerCase() != char2.toLocaleLowerCase()) {
119+
return false;
120+
} else {
121+
++left;
122+
--right;
123+
}
124+
}
125+
return true;
126+
};
127+
```
128+
106129
### **...**
107130

108131
```

solution/0100-0199/0125.Valid Palindrome/README_EN.md

+23
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,29 @@ private:
106106
};
107107
```
108108
109+
### **TypeScript**
110+
111+
```ts
112+
function isPalindrome(s: string): boolean {
113+
let left: number = 0, right: number = s.length - 1;
114+
while (left < right) {
115+
let char1: string = s.charAt(left);
116+
let char2: string = s.charAt(right);
117+
if (!(/[a-zA-Z0-9]/).test(char1)) {
118+
++left;
119+
} else if (!(/[a-zA-Z0-9]/).test(char2)) {
120+
--right;
121+
} else if (char1.toLocaleLowerCase() != char2.toLocaleLowerCase()) {
122+
return false;
123+
} else {
124+
++left;
125+
--right;
126+
}
127+
}
128+
return true;
129+
};
130+
```
131+
109132
### **...**
110133

111134
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function isPalindrome(s: string): boolean {
2+
let left: number = 0, right: number = s.length - 1;
3+
while (left < right) {
4+
let char1: string = s.charAt(left);
5+
let char2: string = s.charAt(right);
6+
if (!(/[a-zA-Z0-9]/).test(char1)) {
7+
++left;
8+
} else if (!(/[a-zA-Z0-9]/).test(char2)) {
9+
--right;
10+
} else if (char1.toLocaleLowerCase() != char2.toLocaleLowerCase()) {
11+
return false;
12+
} else {
13+
++left;
14+
--right;
15+
}
16+
}
17+
return true;
18+
};

0 commit comments

Comments
 (0)