@@ -7,21 +7,21 @@ def constructDistancedSequence(self, n):
7
7
:type n: int
8
8
:rtype: List[int]
9
9
"""
10
- def backtracking (n , i , s , lookup ):
11
- if i == len (s ):
10
+ def backtracking (n , i , result , lookup ):
11
+ if i == len (result ):
12
12
return True
13
- if s [i ]:
14
- return backtracking (n , i + 1 , s , lookup )
13
+ if result [i ]:
14
+ return backtracking (n , i + 1 , result , lookup )
15
15
for x in reversed (xrange (1 , n + 1 )):
16
16
j = i if x == 1 else i + x
17
- if lookup [x ] or j >= len (s ) or s [j ]:
17
+ if lookup [x ] or j >= len (result ) or result [j ]:
18
18
continue
19
- s [i ], s [j ], lookup [x ] = x , x , True
20
- if backtracking (n , i + 1 , s , lookup ):
19
+ result [i ], result [j ], lookup [x ] = x , x , True
20
+ if backtracking (n , i + 1 , result , lookup ):
21
21
return True
22
- s [i ], s [j ], lookup [x ] = 0 , 0 , False
22
+ result [i ], result [j ], lookup [x ] = 0 , 0 , False
23
23
return False
24
24
25
- s , lookup = [0 ]* (2 * n - 1 ), [False ]* (n + 1 )
26
- backtracking (n , 0 , s , lookup )
27
- return s
25
+ result , lookup = [0 ]* (2 * n - 1 ), [False ]* (n + 1 )
26
+ backtracking (n , 0 , result , lookup )
27
+ return result
0 commit comments