题解 | #牛群排列组合#

牛群排列组合

https://www.nowcoder.com/practice/3db87961faf34094b5115775be588126

from ctypes import resize
import re
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param nums int整型一维数组 
# @return int整型二维数组
#
class Solution:
    def cow_permutation(self , nums: List[int]) -> List[List[int]]:
        # write code here
 
        nums.sort(reverse=True)
        path=[]
        result=[]
        print(nums)
        used=[False]*len(nums)
        self.backtracking(nums,path,result,used)
        return result
    def backtracking(self,nums,path,result,used):
        if len(path)==len(nums):
            result.append(path[:])
            return
        for i in range(len(nums)):
            if i>0 and nums[i]==nums[i-1] and used[i-1]==False:
                continue
            if used[i]==True:
                continue
            used[i]=True
            path.append(nums[i])
            self.backtracking(nums,path,result,used)
            path.pop()
            used[i]=False





#刷题#
全部评论

相关推荐

06-18 13:28
已编辑
门头沟学院 Web前端
爱睡觉的冰箱哥:《给予你300的工资》,阴的没边了
点赞 评论 收藏
分享
05-16 11:16
已编辑
东华理工大学 Java
牛客73769814...:盲猜几十人小公司,庙小妖风大,咋不叫她去4️⃣呢😁
牛客创作赏金赛
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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