2801. Count Stepping Numbers in Range Hard
1/**
2 * [2801] Count Stepping Numbers in Range
3 *
4 * Given two positive integers low and high represented as strings, find the count of stepping numbers in the inclusive range [low, high].
5 * A stepping number is an integer such that all of its adjacent digits have an absolute difference of exactly 1.
6 * Return an integer denoting the count of stepping numbers in the inclusive range [low, high].
7 * Since the answer may be very large, return it modulo 10^9 + 7.
8 * Note: A stepping number should not have a leading zero.
9 *
10 * <strong class="example">Example 1:
11 *
12 * Input: low = "1", high = "11"
13 * Output: 10
14 * 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.
15 * <strong class="example">Example 2:
16 *
17 * Input: low = "90", high = "101"
18 * Output: 2
19 * 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.
20 *
21 * Constraints:
22 *
23 * 1 <= int(low) <= int(high) < 10^100
24 * 1 <= low.length, high.length <= 100
25 * low and high consist of only digits.
26 * low and high don't have any leading zeros.
27 *
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/count-stepping-numbers-in-range/
32// discuss: https://leetcode.com/problems/count-stepping-numbers-in-range/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37 pub fn count_stepping_numbers(low: String, high: String) -> i32 {
38 0
39 }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn test_2801() {
50 }
51}
52
Back
© 2025 bowen.ge All Rights Reserved.