131. Palindrome Partitioning
# Medium
Last updated
Was this helpful?
# Medium
Last updated
Was this helpful?
定义一个subs为string类型,相当于子集集合里的每个字符串,每次多加一个字母,判断是否是回文,不是的话继续加一个后面的字母,如果是回文,就加入子集集合中。若是碰到了return就回溯到是回文的状态,尝试别的可能的组合。
sub = ''
非常需要思考放在哪里?遗留问题。
helper函数的终止条件if index == len(s)
string = string[:-1]
is to delete the last element of a string;
list.pop()
is to delete the last element of a list
can sacrifice space to compute isParlindrome before backtracking, T = O(2^n)