File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change 1
1
# Learn Python together
2
- """ Given an array nums of distinct integers, return all the possible permutations. """
3
2
3
+ """ Given an array nums of distinct integers, return all the possible permutations.
4
+ """
4
5
# Solution 1 using loop and recursive
5
6
6
7
def permute (nums ):
@@ -9,10 +10,14 @@ def permute(nums):
9
10
result = [] # empty list
10
11
# iteration through each item in the list
11
12
for i in range (len (nums )):
12
- lis = nums [i ] # giving value at index i in lis variable
13
- new_list = nums [:i ]+ nums [i + 1 :] # giving in new list all elemts of the list exclude lis
14
- for perm in permute (new_list ): # recursive call function for creating permutation
15
- result .append ([lis ]+ perm ) # add variables to result
13
+ # giving value at index i in lis variable
14
+ lis = nums [i ]
15
+ # giving in new list all elemts of the list exclude lis
16
+ new_list = nums [:i ]+ nums [i + 1 :]
17
+ # recursive call function for creating permutation
18
+ for perm in permute (new_list ):
19
+ # add variables to result
20
+ result .append ([lis ]+ perm )
16
21
return result
17
22
18
23
#check
You can’t perform that action at this time.
0 commit comments