1291. Sequential Digits
Python
Time: O(1)
Space: O(1)
class Solution:
def sequentialDigits(self, low: int, high: int) -> List[int]:
digits = [str(digit) for digit in range(1, 10)]
result = []
for i in range(0, 9):
for j in range(i, 9):
num = int(''.join(digits[i:j+1]))
if num >= low and num <= high:
result.append(num)
return sorted(result)