Description

Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.

Examples

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

Two valid partitions: 'a'+'a'+'b' and 'aa'+'b'.

Input:s = "a"
Output:[["a"]]
Explanation:

Single character is a palindrome.

Input:s = "racecar"
Output:[["r","a","c","e","c","a","r"],["r","a","cec","a","r"],["r","aceca","r"],["racecar"]]
Explanation:

This string can be partitioned in multiple ways: each character individually, grouping the middle palindrome 'cec', grouping the larger palindrome 'aceca', or keeping the entire string as one palindrome since 'racecar' itself is a palindrome.

Constraints

  • 1 ≤ s.length ≤ 16
  • s contains only lowercase English letters.

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!