Palindrome Partitioning II

Given a string s, return the minimum number of cuts needed to partition s such that every substring in the partition is a palindrome. Pattern focus: Palindrome partitioning. This is the classic minimum-cut dynamic programming problem on palindromic substrings.

Input Format

s = input string

Output Format

minimum number of cuts

Constraints

  • 1 <= s.length <= 2000
  • s contains lowercase English letters.

Examples

Example 1:

Input:

s = "aab"

Output:

1

Explanation:

Partition as aa | b.

Example 2:

Input:

s = "a"

Output:

0

Explanation:

A single character is already a palindrome.

Loading...
Palindrome Partitioning II - Dp Strings