[
backtracking
queue
]
BinarySearch 0901 Contiguously Increasing Numbers
Problem statement
https://binarysearch.com/problems/Contiguously-Increasing-Numbers/
Solution
Equal to Leetcode 1291. Sequential Digits.
Complexity
It is O(1)
for time and space.
Code
class Solution:
def solve(self, low, high):
out = []
queue = deque(range(1, 10))
while queue:
elem = queue.popleft()
if low <= elem <= high:
out.append(elem)
last = elem % 10
if last < 9: queue.append(elem*10 + last + 1)
return out