File tree 3 files changed +61
-0
lines changed
solution/0600-0699/0680.Valid Palindrome II
3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,28 @@ class Solution {
86
86
}
87
87
```
88
88
89
+ ### ** TypeScript**
90
+
91
+ ``` ts
92
+ function validPalindrome(s : string ): boolean {
93
+ for (let i: number = 0 , j = s .length - 1 ; i < j ; ++ i , -- j ) {
94
+ if (s .charAt (i ) != s .charAt (j )) {
95
+ return isPalinddrome (s .slice (i , j )) || isPalinddrome (s .slice (i + 1 , j + 1 ));
96
+ }
97
+ }
98
+ return true ;
99
+ };
100
+
101
+ function isPalinddrome(s : string ): boolean {
102
+ for (let i: number = 0 , j = s .length - 1 ; i < j ; ++ i , -- j ) {
103
+ if (s .charAt (i ) != s .charAt (j )) {
104
+ return false ;
105
+ }
106
+ }
107
+ return true ;
108
+ }
109
+ ```
110
+
89
111
### ** ...**
90
112
91
113
```
Original file line number Diff line number Diff line change @@ -99,6 +99,28 @@ class Solution {
99
99
}
100
100
```
101
101
102
+ ### ** TypeScript**
103
+
104
+ ``` ts
105
+ function validPalindrome(s : string ): boolean {
106
+ for (let i: number = 0 , j = s .length - 1 ; i < j ; ++ i , -- j ) {
107
+ if (s .charAt (i ) != s .charAt (j )) {
108
+ return isPalinddrome (s .slice (i , j )) || isPalinddrome (s .slice (i + 1 , j + 1 ));
109
+ }
110
+ }
111
+ return true ;
112
+ };
113
+
114
+ function isPalinddrome(s : string ): boolean {
115
+ for (let i: number = 0 , j = s .length - 1 ; i < j ; ++ i , -- j ) {
116
+ if (s .charAt (i ) != s .charAt (j )) {
117
+ return false ;
118
+ }
119
+ }
120
+ return true ;
121
+ }
122
+ ```
123
+
102
124
### ** ...**
103
125
104
126
```
Original file line number Diff line number Diff line change
1
+ function validPalindrome ( s : string ) : boolean {
2
+ for ( let i : number = 0 , j = s . length - 1 ; i < j ; ++ i , -- j ) {
3
+ if ( s . charAt ( i ) != s . charAt ( j ) ) {
4
+ return isPalinddrome ( s . slice ( i , j ) ) || isPalinddrome ( s . slice ( i + 1 , j + 1 ) ) ;
5
+ }
6
+ }
7
+ return true ;
8
+ } ;
9
+
10
+ function isPalinddrome ( s : string ) : boolean {
11
+ for ( let i : number = 0 , j = s . length - 1 ; i < j ; ++ i , -- j ) {
12
+ if ( s . charAt ( i ) != s . charAt ( j ) ) {
13
+ return false ;
14
+ }
15
+ }
16
+ return true ;
17
+ }
You can’t perform that action at this time.
0 commit comments