Skip to content

Commit 4816025

Browse files
committed
feat: add solutions to lc problem: No.1147
1 parent fbcbec3 commit 4816025

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

solution/1100-1199/1147.Longest Chunked Palindrome Decomposition/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,23 @@ func longestDecomposition(text string) int {
170170
}
171171
```
172172

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+
173190
### **...**
174191

175192
```

solution/1100-1199/1147.Longest Chunked Palindrome Decomposition/README_EN.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,23 @@ func longestDecomposition(text string) int {
154154
}
155155
```
156156

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+
157174
### **...**
158175

159176
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
}

0 commit comments

Comments
 (0)