java.lang.Object
g2801_2900.s2801_count_stepping_numbers_in_range.Solution

public class Solution extends Object
2801 - Count Stepping Numbers in Range.<p>Hard</p> <p>Given two positive integers <code>low</code> and <code>high</code> represented as strings, find the count of <strong>stepping numbers</strong> in the inclusive range <code>[low, high]</code>.</p> <p>A <strong>stepping number</strong> is an integer such that all of its adjacent digits have an absolute difference of <strong>exactly</strong> <code>1</code>.</p> <p>Return <em>an integer denoting the count of stepping numbers in the inclusive range</em> <code>[low, high]</code><em>.</em></p> <p>Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p> <p><strong>Note:</strong> A stepping number should not have a leading zero.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> low = &ldquo;1&rdquo;, high = &ldquo;11&rdquo;</p> <p><strong>Output:</strong> 10</p> <p><strong>Explanation:</strong> 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.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> low = &ldquo;90&rdquo;, high = &ldquo;101&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> 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.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= int(low) <= int(high) < 10<sup>100</sup></code></li> <li><code>1 <= low.length, high.length <= 100</code></li> <li><code>low</code> and <code>high</code> consist of only digits.</li> <li><code>low</code> and <code>high</code> don&rsquo;t have any leading zeros.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • countSteppingNumbers

      public int countSteppingNumbers(String low, String high)