<p>An&nbsp;integer has <em>sequential digits</em> if and only if each digit in the number is one more than the previous digit.</p>

<p>Return a <strong>sorted</strong> list of all the integers&nbsp;in the range <code>[low, high]</code>&nbsp;inclusive that have sequential digits.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> low = 100, high = 300
<strong>Output:</strong> [123,234]
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> low = 1000, high = 13000
<strong>Output:</strong> [1234,2345,3456,4567,5678,6789,12345]
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>10 &lt;= low &lt;= high &lt;= 10^9</code></li>
</ul>

class Solution {

    int numDigits(int n)
    {
        int res = 1;
        while (n /= 10)
            ++res;
        return res;
    }

    int getSequential(int numDigits, int offset = 0)
    {
        int res = 0;
        for (int i = 1; i <= numDigits; ++i)
        {
            res = res * 10 + i + offset;
        }
        return res;
    }

public:
    vector<int> sequentialDigits(int low, int high) {

        // Run: 33% O(n * d) | Mem: O(n * d)
        int d1 = numDigits(low);
        int d2 = numDigits(high);

        vector<int> res;
        while (d1 <= d2)
        {
            for (int i = 0; i < 10 - d1; ++i)
            {
                int next = getSequential(d1, i);
                if (next < low)
                    continue;
                if (next > high)
                    return res;
                res.push_back(next);
            }
            ++d1;
        }     
        return res;
    }
};
7300