Skip to content

Commit fff0be4

Browse files
authored
Update construct-the-lexicographically-largest-valid-sequence.py
1 parent 0c2bf1e commit fff0be4

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

Python/construct-the-lexicographically-largest-valid-sequence.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ def constructDistancedSequence(self, n):
77
:type n: int
88
:rtype: List[int]
99
"""
10-
def backtracking(n, i, s, lookup):
11-
if i == len(s):
10+
def backtracking(n, i, result, lookup):
11+
if i == len(result):
1212
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)
1515
for x in reversed(xrange(1, n+1)):
1616
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]:
1818
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):
2121
return True
22-
s[i], s[j], lookup[x] = 0, 0, False
22+
result[i], result[j], lookup[x] = 0, 0, False
2323
return False
2424

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

Comments
 (0)