-
-
Notifications
You must be signed in to change notification settings - Fork 297
/
Copy path1215.py
23 lines (22 loc) · 820 Bytes
/
1215.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
__________________________________________________________________________________________________
304ms
class Solution:
def countSteppingNumbers(self, low: int, high: int) -> List[int]:
def dfs(n):
if n > high:
return
q.add(n)
d = n % 10
if d == 0:
dfs(n * 10 + 1)
elif d == 9:
dfs(n * 10 + 8)
else:
dfs(n * 10 + d + 1)
dfs(n * 10 + d - 1)
q = set()
for i in range(10):
dfs(i)
return sorted(v for v in q if v >= low)
__________________________________________________________________________________________________
__________________________________________________________________________________________________