132. Palindrome Partitioning II
LeetCode 132. Palindrome Partitioning II
Description
Given a string s
, partition s
such that every substring of the partition is a palindrome.
Return the minimum cuts needed for a palindrome partitioning of s
.
Example 1:
Example 2:
Constraints:
1 <= s.length <= 2000
s
consists of lower-case English letters only.
Tags
Dynamic Programming
Solution
We denote as the least number of cuts s[0..i]
needs. We can formulate its transition function as below:
There is an edge case leads when .
We also use a 2D array to determine every substring that whether it is a palindrome, with the dynamic programming solver below:
Complexity
Time complexity:
Space complexity:
Code
Reference
Last updated
Was this helpful?