# LeetCode Palindrome Partitioning

Source: Internet
Author: User

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"]

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.