MCPcopy
hub / github.com/doocs/leetcode / dfs

Method dfs

solution/3400-3499/3437.Permutations III/Solution.py:3–13  ·  view source on GitHub ↗
(i: int)

Source from the content-addressed store, hash-verified

1class Solution:
2 def permute(self, n: int) -> List[List[int]]:
3 def dfs(i: int) -> None:
4 if i >= n:
5 ans.append(t[:])
6 return
7 for j in range(1, n + 1):
8 if not vis[j] and (i == 0 or t[-1] % 2 != j % 2):
9 t.append(j)
10 vis[j] = True
11 dfs(i + 1)
12 vis[j] = False
13 t.pop()
14
15 ans = []
16 t = []

Callers

nothing calls this directly

Calls 3

dfsFunction · 0.70
appendMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected