Skip to content

Commit f2f4e03

Browse files
committed
add palindrome partition ii
1 parent 818d587 commit f2f4e03

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

palindrome-partitioning-ii/README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1+
## [Longest Palindromic Substring](../longest-palindromic-substring) + [Word Break](../word-break)
12

2-
## TODO
3-
* write down thinking
3+
After running [Longest Palindromic Substring](../longest-palindromic-substring),
4+
we got a table `P[len][index]`, that is, we can tell if `s[i..j]` is palindromic
45

6+
## Apply [Word Break](../word-break)
7+
8+
`M[i]` means the mincut of `s[0..i]`.
9+
10+
When a new char comes, we have 3 choices:
11+
12+
* `M[i + 1] = 0`: if `s[0..i + 1]` is palindromic
13+
* `M[i + 1] = M[i] + 1`: cut at `i`, between the old string `s[0..i]` and the new char.
14+
* `M[i + 1] = M[j] + 1`: cut at `j`, `j from 0 -> i`, such that `s[j..i+1]` is palindromic, between the `s[0..j]` and `s[j..i + 1]`.
15+
16+
Our job is to find the minimum value among them.

0 commit comments

Comments
 (0)