#2801
Count Stepping Numbers in Range
international master · 2030 · lc hard +32 · verified · 27.8% accepted · 356 likes · top 6%
Description
Two positive integers low and high are given as strings. Count all stepping numbers in the inclusive range [low, high].
A stepping number is a positive integer in which every pair of adjacent digits differs by exactly 1.
Return the count modulo 109 + 7.
Note: Stepping numbers must not have leading zeros.
Example 1:
Input: low = "1", high = "11"
Output: 10
Explanation: The stepping numbers in the range [1,11] are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10. There are a total of 10 stepping numbers in the range. Hence, the output is 10.
Example 2:
Input: low = "90", high = "101"
Output: 2
Explanation: The stepping numbers in the range [90,101] are 98 and 101. There are a total of 2 stepping numbers in the range. Hence, the output is 2.
Code
1
2
3