<p>Given two integers n and k, return <em>an array of all the integers of length </em><code>n</code><em> where the difference between every two consecutive digits is </em><code>k</code>. You may return the answer in <strong>any order</strong>.</p>

<p>Note that the integers should not have leading zeros. Integers as <code>02</code> and <code>043</code> are not allowed.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> n = 3, k = 7
<strong>Output:</strong> [181,292,707,818,929]
<strong>Explanation:</strong> Note that 070 is not a valid number, because it has leading zeroes.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> n = 2, k = 1
<strong>Output:</strong> [10,12,21,23,32,34,43,45,54,56,65,67,76,78,87,89,98]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>2 &lt;= n &lt;= 9</code></li>
	<li><code>0 &lt;= k &lt;= 9</code></li>
</ul>

class Solution {
public:
    void backtracking(vector<vector<int>> &v, vector<int> &current, int n, int k) {
        int size = current.size();
        if (size == n) {
            v.push_back(current);
            return;
        }
        int prev = current[size - 1];
        int next;
        for (int t = -k; t <= k; t += 2 * k) {
            next = prev + t;
            if (next >= 0 && next <= 9) {
                current.push_back(next);
                backtracking(v, current, n, k);
                current.pop_back();
            }
        }

    }

    int convert(vector<int> current) {
        int answer = 0;
        int size = current.size();
        int d = 1;
        int t = 10;
        for (int i = size - 1; i >= 0; --i) {
            answer += current[i] * d;
            d *= t;
        }

        return answer;
    }

    vector<int> numsSameConsecDiff(int n, int k) {
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
        cout.tie(nullptr);

        vector<int> answer;
        vector<vector<int>> v;
        if (k == 0) {
            for (int i = 1; i <= 9; ++i) {
                vector<int> current;
                for (int j = 0; j < n; ++j) {
                    current.push_back(i);
                }
                v.push_back(current);
            }
        } else {
            for (int i = 1; i <= 9; ++i) {
                vector<int> current = {i};
                backtracking(v, current, n, k);
            }
        }


        for (vector<int> current: v) {
            answer.push_back(convert(current));
        }

        return answer;
    }
};
11800