Leetcode 1212 Solution

This article provides solution to leetcode question 1212 (sequential-digits)

https://leetcode.com/problems/sequential-digits

Solution

class Solution:
    def sequentialDigits(self, low: int, high: int) -> List[int]:
        ans = []
        for i in range(1, 10):
            j = i
            curr_num = str(j)

            while int(curr_num) <= high:
                if int(curr_num) >= low:
                    ans.append(int(curr_num))

                if j == 9:
                    break

                j += 1
                curr_num += str(j)

        return sorted(ans)