File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed
solution/1100-1199/1147.Longest Chunked Palindrome Decomposition Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -170,6 +170,23 @@ func longestDecomposition(text string) int {
170
170
}
171
171
```
172
172
173
+ ### ** TypeScript**
174
+
175
+ ``` ts
176
+ function longestDecomposition(text : string ): number {
177
+ const n: number = text .length ;
178
+ if (n < 2 ) {
179
+ return n ;
180
+ }
181
+ for (let i: number = 1 ; i <= n >> 1 ; i ++ ) {
182
+ if (text .slice (0 , i ) === text .slice (n - i )) {
183
+ return 2 + longestDecomposition (text .slice (i , n - i ));
184
+ }
185
+ }
186
+ return 1 ;
187
+ }
188
+ ```
189
+
173
190
### ** ...**
174
191
175
192
```
Original file line number Diff line number Diff line change @@ -154,6 +154,23 @@ func longestDecomposition(text string) int {
154
154
}
155
155
```
156
156
157
+ ### ** TypeScript**
158
+
159
+ ``` ts
160
+ function longestDecomposition(text : string ): number {
161
+ const n: number = text .length ;
162
+ if (n < 2 ) {
163
+ return n ;
164
+ }
165
+ for (let i: number = 1 ; i <= n >> 1 ; i ++ ) {
166
+ if (text .slice (0 , i ) === text .slice (n - i )) {
167
+ return 2 + longestDecomposition (text .slice (i , n - i ));
168
+ }
169
+ }
170
+ return 1 ;
171
+ }
172
+ ```
173
+
157
174
### ** ...**
158
175
159
176
```
Original file line number Diff line number Diff line change
1
+ function longestDecomposition ( text : string ) : number {
2
+ const n : number = text . length ;
3
+ if ( n < 2 ) {
4
+ return n ;
5
+ }
6
+ for ( let i : number = 1 ; i <= n >> 1 ; i ++ ) {
7
+ if ( text . slice ( 0 , i ) === text . slice ( n - i ) ) {
8
+ return 2 + longestDecomposition ( text . slice ( i , n - i ) ) ;
9
+ }
10
+ }
11
+ return 1 ;
12
+ }
You can’t perform that action at this time.
0 commit comments