Open NicolaBernini opened 4 years ago
def permutate_pf(v, res, l=0):
if l==len(v)-1:
res.append(v)
return
for i in range(l, len(v)):
t = []
t.append(v[i])
for j in range(len(v)):
if(j!=i):
t.append(v[j])
permutate_pf(t, res, l+1)
res = []
permutate_pf([1,2,3], res)
print(res)
Run it on Ideone
CPP
Using Backtracking
Using Putfirst Method
Check
Run it on Ideone