Palindrome Partitioning Posted on 2018-09-09 Descriptionhttps://leetcode.com/problems/palindrome-partitioning/description/ Solution123456789101112131415161718192021222324252627282930313233343536class Solution(object): def partition(self, s): """ :type s: str :rtype: List[List[str]] """ ret = [] st = [] if s is None or len(s) == 0: return [] self.explore(0, s, st, ret) return ret def valid(self, s, start, end): if end == start: return True middle = (start + end + 1) / 2 for i in range(start, middle): if s[i] != s[start + end - i]: return False return True def explore(self, start, s, st, ret): if start == len(s): ret.append(st[:]) return for end in range(start, len(s)): if self.valid(s, start, end) is False: continue st.append(s[start: end + 1]) self.explore(end + 1, s, st, ret) st.pop() return