Class Solution
java.lang.Object
g2301_2400.s2310_sum_of_numbers_with_units_digit_k.Solution
2310 - Sum of Numbers With Units Digit K.<p>Medium</p>
<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><strong>Example 1:</strong></p>
<p><strong>Input:</strong> num = 58, k = 9</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong></p>
<p>One valid set is [9,49], as the sum is 58 and each integer has a units digit of 9.</p>
<p>Another valid set is [19,39].</p>
<p>It can be shown that 2 is the minimum possible size of a valid set.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> num = 37, k = 2</p>
<p><strong>Output:</strong> -1</p>
<p><strong>Explanation:</strong> It is not possible to obtain a sum of 37 using only integers that have a units digit of 2.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> num = 0, k = 7</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong> The sum of an empty set is considered 0.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>0 <= num <= 3000</code></li>
<li><code>0 <= k <= 9</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minimumNumbers
public int minimumNumbers(int nums, int k)
-