题解 | #没有重复项数字的全排列#

没有重复项数字的全排列

http://www.nowcoder.com/practice/4bcf3081067a4d028f95acee3ddcd2b1

class Solution:
    result = []
    # 跟踪回溯
    def trace(self,path,choice):
        # 符合要求 加入result
        if len(path) == len(choice):
            self.result.append(path[:])
            return
        # 循环选择
        for item in choice:
            # 剪枝判断
            if item in path: continue
            path.append(item)
            # 选择下一个数
            self.trace(path,choice)
            # 回溯
            path.pop()
    def permute(self , num: List[int]) -> List[List[int]]:
        # 排序
        num.sort() 
        # 回溯
        self.trace([], num) 
        return self.result
全部评论

相关推荐

04-09 09:47
门头沟学院 Java
Arbelite_:2-3k,这工资还不如去摇奶茶
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务