Loading...
Loading...
You are given two positive integers low and high, each written as a string of digits with no leading zero.
Call a positive integer a unit-step number when every pair of adjacent digits of its decimal form differs by exactly 1. A one-digit positive integer has no adjacent pair, so every one of them is a unit-step number. A unit-step number never has a leading zero.
Return how many unit-step numbers x satisfy low <= x <= high. Mod the result by 10 ** 9 + 7.
Input: low = "1", high = "11"
Output: 10
Explanation: The unit-step numbers from 1 to 11 are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10.
10 qualifies because 1 and 0 differ by 1. 11 does not, because its two digits differ by 0.
Input: low = "90", high = "101"
Output: 2
Explanation: The unit-step numbers from 90 to 101 are 98 and 101.
98 qualifies because 9 and 8 differ by 1. 101 qualifies because 1 and 0 differ by 1, and 0 and 1 differ by 1.
Every other value in the range has some adjacent pair that differs by 0 or by more than 1.
int(low) ≤ int(high) <10100low.length, high.length ≤100low and high consist of digits only.low and high have no leading zeros.