题解 | #牛群排列组合#
牛群排列组合
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#刷题#