mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 15:31:43 +08:00
48 lines
2.0 KiB
HTML
48 lines
2.0 KiB
HTML
<p>You are given two integers, <code>l</code> and <code>r</code>, represented as strings, and an integer <code>b</code>. Return the count of integers in the inclusive range <code>[l, r]</code> whose digits are in <strong>non-decreasing</strong> order when represented in base <code>b</code>.</p>
|
|
|
|
<p>An integer is considered to have <strong>non-decreasing</strong> digits if, when read from left to right (from the most significant digit to the least significant digit), each digit is greater than or equal to the previous one.</p>
|
|
|
|
<p>Since the answer may be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">l = "23", r = "28", b = 8</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">3</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<ul>
|
|
<li>The numbers from 23 to 28 in base 8 are: 27, 30, 31, 32, 33, and 34.</li>
|
|
<li>Out of these, 27, 33, and 34 have non-decreasing digits. Hence, the output is 3.</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">l = "2", r = "7", b = 2</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<ul>
|
|
<li>The numbers from 2 to 7 in base 2 are: 10, 11, 100, 101, 110, and 111.</li>
|
|
<li>Out of these, 11 and 111 have non-decreasing digits. Hence, the output is 2.</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code><font face="monospace">1 <= l.length <= r.length <= 100</font></code></li>
|
|
<li><code>2 <= b <= 10</code></li>
|
|
<li><code>l</code> and <code>r</code> consist only of digits.</li>
|
|
<li>The value represented by <code>l</code> is less than or equal to the value represented by <code>r</code>.</li>
|
|
<li><code>l</code> and <code>r</code> do not contain leading zeros.</li>
|
|
</ul>
|