cheetcode

77. Palindrome PartitioningMedium

Split a string into every possible list of palindromic substrings.

Given a string, partition it so that every substring in the partition is a palindrome.

Return all possible palindrome partitions. The runner accepts the partitions in any order.

Build one partial choice at a time, recurse, then undo that choice before exploring the next option. Pay close attention to duplicate handling and stopping conditions.

Examples

Input: s = "aab"
Output: [["a","a","b"],["aa","b"]]
Input: s = "a"
Output: [["a"]]

Constraints

  • 1 <= s.length <= 16
  • s contains only lowercase English letters.