LeetCode Palindrome Partitioning
Palindrome Partitioning for solving LeetCode Problems
Original question
Splits a string into several sub-strings so that the sub-strings are all input strings. All the splitting schemes must be listed.
Note:
None
Example:
Input: s = "aab"
Output: result = [["a", "a", "B"], ["aa", "B"]
Solutions
The simplest recursion method is used to divide a string into the first and second parts. If the first part is a retrieval string, the second part is split and recursive continuously, until the recursion termination condition-the string is null. If the first part is not a return string, try the following segmentation method.
AC Source Code
Class Solution (object): def partition (self, s): "": type s: str: rtype: List [List [str] "" if not s: return [[] result = [] for I in range (len (s): if self. isPalindrome (s [: I + 1]): for r in self. partition (s [I + 1:]): result. append ([s [: I + 1] + r) return result def isPalindrome (self, s): return s = s [:: -1] if _ name _ = "_ main _": assert Solution (). partition ("aab") = [["a", "a", "B"], ["aa", "B"]