Skip to content

Commit 47067df

Browse files
add 1147
1 parent eb28b59 commit 47067df

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -468,4 +468,5 @@ LeetCode
468468
|1140|[Stone Game II](https://leetcode.com/problems/stone-game-ii/) | c | [c++](./src/1140-Stone-Game-II/1140.cpp) |[python](./src/1140-Stone-Game-II/1140.py)|[go](./src/1140-Stone-Game-II/1140.go)|[js](./src/1140-Stone-Game-II/1140.js)|Medium|
469469
|1144|[Decrease Elements To Make Array Zigzag](https://leetcode.com/problems/decrease-elements-to-make-array-zigzag/) | c | [c++](./src/1144-Decrease-Elements-To-Make-Array-Zigzag/1144.cpp) |[python](./src/1144-Decrease-Elements-To-Make-Array-Zigzag/1144.py)|[go](./src/1144-Decrease-Elements-To-Make-Array-Zigzag/1144.go)|[js](./src/1144-Decrease-Elements-To-Make-Array-Zigzag/1144.js)|Medium|
470470
|1145|[Binary Tree Coloring Game](https://leetcode.com/problems/binary-tree-coloring-game/) | c | [c++](./src/1145-Binary-Tree-Coloring-Game/1145.cpp) |[python](./src/1145-Binary-Tree-Coloring-Game/1145.py)|[go](./src/1145-Binary-Tree-Coloring-Game/1145.go)|[js](./src/1145-Binary-Tree-Coloring-Game/1145.js)|Medium|
471-
|1146|[Snapshot Array](https://leetcode.com/problems/snapshot-array/) | c | [c++](./src/1146-Snapshot-Array/1146.cpp) |[python](./src/1146-Snapshot-Array/1146.py)|[go](./src/1146-Snapshot-Array/1146.go)|[js](./src/1146-Snapshot-Array/1146.js)|Medium|
471+
|1146|[Snapshot Array](https://leetcode.com/problems/snapshot-array/) | c | [c++](./src/1146-Snapshot-Array/1146.cpp) |[python](./src/1146-Snapshot-Array/1146.py)|[go](./src/1146-Snapshot-Array/1146.go)|[js](./src/1146-Snapshot-Array/1146.js)|Medium|
472+
|1147|[Longest Chunked Palindrome Decomposition](https://leetcode.com/problems/longest-chunked-palindrome-decomposition/) | c | [c++](./src/1147-Longest-Chunked-Palindrome-Decomposition/1147.cpp) |[python](./src/1147-Longest-Chunked-Palindrome-Decomposition/1147.py)|[go](./src/1147-Longest-Chunked-Palindrome-Decomposition/1147.go)|[js](./src/1147-Longest-Chunked-Palindrome-Decomposition/1147.js)|Hard|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution
2+
{
3+
public:
4+
int longestDecomposition(string text)
5+
{
6+
int n = text.size();
7+
for (int i = 1; i <= n/2; ++i)
8+
{
9+
if (text.substr(0,i) == text.substr(n-i))
10+
return 2 + longestDecomposition(text.substr(i,n-2*i));
11+
}
12+
return n == 0 ? 0 : 1;
13+
}
14+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
func longestDecomposition(text string) int {
2+
var n = len(text);
3+
for i := 1; i <= n/2; i++ {
4+
if text[:i] == text[n-i:] {
5+
return 2 + longestDecomposition(text[i:n-i])
6+
}
7+
}
8+
if n == 0 {
9+
return 0
10+
}
11+
return 1
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var longestDecomposition = function(text) {
2+
var n = text.length;
3+
for (var i = 1; i <= n/2; ++i) {
4+
if (text.substr(0,i) == text.substr(n-i))
5+
return 2 + longestDecomposition(text.substr(i,n-2*i));
6+
}
7+
return n == 0 ? 0 : 1;
8+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution:
2+
def longestDecomposition(self, text: str) -> int:
3+
n = len(text)
4+
for i in range(1, n//2 + 1):
5+
if text[:i] == text[n-i:]:
6+
return 2 + self.longestDecomposition(text[i:n-i])
7+
return 0 if n == 0 else 1

0 commit comments

Comments
 (0)