MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / permute

Method permute

python/0046-permutations.py:2–17  ·  view source on GitHub ↗
(self, nums: List[int])

Source from the content-addressed store, hash-verified

1class Solution:
2 def permute(self, nums: List[int]) -> List[List[int]]:
3 res = []
4
5 # base case
6 if len(nums) == 1:
7 return [nums[:]] # nums[:] is a deep copy
8
9 for i in range(len(nums)):
10 n = nums.pop(0)
11 perms = self.permute(nums)
12
13 for perm in perms:
14 perm.append(n)
15 res.extend(perms)
16 nums.append(n)
17 return res

Callers

nothing calls this directly

Calls 1

popMethod · 0.45

Tested by

no test coverage detected