Palindrome Partitioning II
HardP3Coding
Cut s into consecutive pieces so that every piece is a palindrome. Return the minimum number of cuts needed. A string that is already a palindrome needs 0 cuts.
Example 1
- Input
- s = "aab"
- Output
- 1
- Why
- Cut once to get "aa" and "b".
Example 2
- Input
- s = "a"
- Output
- 0
Example 3
- Input
- s = "ab"
- Output
- 1
Constraints
- 1 <= s.length <= 2000
scontains lowercase English letters.
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 11. ⌘Enter runs, ⌘⇧Enter submits.