Palindrome Partitioning
MediumP2Coding
Split s into consecutive pieces so that every piece is a palindrome. Return every possible split, in any order. Each split is an array of the pieces in the order they appear in s.
Example 1
- Input
- s = "aab"
- Output
- [["a","a","b"],["aa","b"]]
- Why
- Two valid splits: all single letters, or aa + b.
Example 2
- Input
- s = "a"
- Output
- [["a"]]
Example 3
- Input
- s = "aa"
- Output
- [["a","a"],["aa"]]
Constraints
- 1 <= s.length <= 12
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 10. ⌘Enter runs, ⌘⇧Enter submits.