Skip to content

Update permutations.py #8102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 31, 2023
Prev Previous commit
Next Next commit
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 26, 2023
commit ba7380489c9dd87b699078a8dca09ed9ece293a7
11 changes: 8 additions & 3 deletions data_structures/arrays/permutations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import List
def permute(nums: List[int]) -> List[List[int]]:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove from typing import List as it is unused , creating pre-commit error.


def permute(nums: list[int]) -> list[list[int]]:
"""
Return all permutations.

Expand All @@ -8,6 +10,7 @@ def permute(nums: List[int]) -> List[List[int]]:
>>> all(list(nums) in permute(numbers) for nums in permutations(numbers))
True
"""

def backtrack(first=0):
if first == n:
output.append(nums[:])
Expand All @@ -21,10 +24,12 @@ def backtrack(first=0):
backtrack()
return output


# return result


if __name__ == "__main__":
import doctest
res = permute([1,2,3])

res = permute([1, 2, 3])
print(res)
doctest.testmod()