mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
* Fixes #9014 * Fixed permute_recursive() by passing nums.copy()
This commit is contained in:
parent
5f8d1cb5c9
commit
320d895b86
|
@ -10,7 +10,7 @@ def permute_recursive(nums: list[int]) -> list[list[int]]:
|
||||||
return [[]]
|
return [[]]
|
||||||
for _ in range(len(nums)):
|
for _ in range(len(nums)):
|
||||||
n = nums.pop(0)
|
n = nums.pop(0)
|
||||||
permutations = permute_recursive(nums)
|
permutations = permute_recursive(nums.copy())
|
||||||
for perm in permutations:
|
for perm in permutations:
|
||||||
perm.append(n)
|
perm.append(n)
|
||||||
result.extend(permutations)
|
result.extend(permutations)
|
||||||
|
@ -43,6 +43,6 @@ def permute_backtrack(nums: list[int]) -> list[list[int]]:
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
res = permute_backtrack([1, 2, 3])
|
result = permute_backtrack([1, 2, 3])
|
||||||
print(res)
|
print(result)
|
||||||
doctest.testmod()
|
doctest.testmod()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user