0
点赞
收藏
分享

微信扫一扫

回溯加递归

科牛 2022-02-01 阅读 43

class Solution(object):
def solvePermutation(self, array):
self.helper(array, [])
def helper(self, array, solution):
# 递归的基线条件
if len(array) == 0:
print(solution)
return
for i in range(len(array)):
newSolution = solution + [array[i]]
self.helper(array[: i] + array[i + 1:], newSolution)
Solution().solvePermutation([“红”, “黄”, “蓝”, “绿”])
在这里插入图片描述

举报

相关推荐

0 条评论