mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
52 lines
1.5 KiB
HTML
52 lines
1.5 KiB
HTML
<p>Given two integers <code>num</code> and <code>k</code>, consider a set of positive integers with the following properties:</p>
|
|
|
|
<ul>
|
|
<li>The units digit of each integer is <code>k</code>.</li>
|
|
<li>The sum of the integers is <code>num</code>.</li>
|
|
</ul>
|
|
|
|
<p>Return <em>the <strong>minimum</strong> possible size of such a set, or </em><code>-1</code><em> if no such set exists.</em></p>
|
|
|
|
<p>Note:</p>
|
|
|
|
<ul>
|
|
<li>The set can contain multiple instances of the same integer, and the sum of an empty set is considered <code>0</code>.</li>
|
|
<li>The <strong>units digit</strong> of a number is the rightmost digit of the number.</li>
|
|
</ul>
|
|
|
|
<p> </p>
|
|
<p><strong>Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> num = 58, k = 9
|
|
<strong>Output:</strong> 2
|
|
<strong>Explanation:</strong>
|
|
One valid set is [9,49], as the sum is 58 and each integer has a units digit of 9.
|
|
Another valid set is [19,39].
|
|
It can be shown that 2 is the minimum possible size of a valid set.
|
|
</pre>
|
|
|
|
<p><strong>Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> num = 37, k = 2
|
|
<strong>Output:</strong> -1
|
|
<strong>Explanation:</strong> It is not possible to obtain a sum of 37 using only integers that have a units digit of 2.
|
|
</pre>
|
|
|
|
<p><strong>Example 3:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> num = 0, k = 7
|
|
<strong>Output:</strong> 0
|
|
<strong>Explanation:</strong> The sum of an empty set is considered 0.
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>0 <= num <= 3000</code></li>
|
|
<li><code>0 <= k <= 9</code></li>
|
|
</ul>
|