Editorial for Permutations


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: wadeyao

def permute(nums):
    if len(nums) == 1:
        return [nums]
    perm = []
    for candi in nums:
        sub_perm = permute([n for n in nums if n != candi])
        for p in sub_perm:
            perm.append([candi] + p)
    return perm

Comments

There are no comments at the moment.