DFS
that takes the current number as a string and the number of digits left to add (n
).n
is 0, add the current number to the result list.k
to the last digit if the result is within [0, 9].k
from the last digit if the result is within [0, 9] and k
is not 0 (to avoid duplicates).DFS
with the updated number and n-1
.DFS
for each digit from 1 to 9 and an initial n
value of n-1
.