Skip to content

Commit 54597c3

Browse files
authored
Create sequential-digits.py
1 parent 71adeab commit 54597c3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Python/sequential-digits.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Time: O((8 + 1) * 8 / 2) = O(1)
2+
# Space: O(8) = O(1)
3+
4+
import collections
5+
6+
7+
class Solution(object):
8+
def sequentialDigits(self, low, high):
9+
"""
10+
:type low: int
11+
:type high: int
12+
:rtype: List[int]
13+
"""
14+
result = []
15+
q = collections.deque(range(1, 9))
16+
while q:
17+
num = q.popleft()
18+
if num > high:
19+
continue
20+
if low <= num:
21+
result.append(num)
22+
if num%10+1 < 10:
23+
q.append(num*10+num%10+1)
24+
return result

0 commit comments

Comments
 (0)