Fixed permute_recursive() by passing nums.copy(). Fixes #9014 (#9161)

* Fixes #9014

* Fixed permute_recursive() by passing nums.copy()
This commit is contained in:
aryan1165 2023-10-01 09:36:15 +05:30 committed by GitHub
parent 5f8d1cb5c9
commit 320d895b86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,7 +10,7 @@ def permute_recursive(nums: list[int]) -> list[list[int]]:
return [[]]
for _ in range(len(nums)):
n = nums.pop(0)
permutations = permute_recursive(nums)
permutations = permute_recursive(nums.copy())
for perm in permutations:
perm.append(n)
result.extend(permutations)
@ -43,6 +43,6 @@ def permute_backtrack(nums: list[int]) -> list[list[int]]:
if __name__ == "__main__":
import doctest
res = permute_backtrack([1, 2, 3])
print(res)
result = permute_backtrack([1, 2, 3])
print(result)
doctest.testmod()