3
List<Integer> res = new ArrayList<>();5
public int[] numsSameConsecDiff(int n, int k) {7
for (int ans = 1; ans < 10; ans++) { // first digit can't be 08
find(ans, n - 1, k); // find remaining n-1 digits using backtrack11
return res.stream().mapToInt(Integer::intValue).toArray(); // convert list to int arr14
private void find(int ans, int n, int k) {17
res.add(ans); // if got length n number then put that into res21
for (int i = 0; i < 10; i++) {22
if (Math.abs(ans % 10 - i) == k) // find digit that have k difference with last digit23
find(ans * 10 + i, n - 1, k);25
ans /= 10; // remove last digit while backtrack