967. Numbers With Same Consecutive Differences
2 years ago in Python
class Solution:
def numsSameConsecDiff(self, n: int, k: int) -> List[int]:
def backtrack():
if len(current) == n:
if current[0] != 0:
result.append(''.join([str(d) for d in current]))
return
for i in range(10):
if current and abs(i - current[-1]) != k:
continue
current.append(i)
backtrack()
current.pop()
result = []
current = []
backtrack()
return result