131. Palindrome Partitioning
Difficulty: Medium
Given a string _s_, partition _s_ such that every substring of the partition is a palindrome.
Return all possible palindrome partitioning of _s_.
Example:
1 | **Input:** "aab" |
在每一步都可以判断中间结果是否为合法结果,用回溯法。
一个长度为 n 的字符串,有 n − 1 个地方可以砍断,每个地方可断可不断,因此复杂度为
O(2n−1)
abc其实只有两个地方可以选择 a|b|c,但是在结束的时候,要单独考虑,把后面的结果加进去
Solution
Language: Java
1 | class Solution { |