2310. Sum of Numbers With Units Digit K Medium
1/**
2 * [2310] Sum of Numbers With Units Digit K
3 *
4 * Given two integers num and k, consider a set of positive integers with the following properties:
5 *
6 * The units digit of each integer is k.
7 * The sum of the integers is num.
8 *
9 * Return the minimum possible size of such a set, or -1 if no such set exists.
10 * Note:
11 *
12 * The set can contain multiple instances of the same integer, and the sum of an empty set is considered 0.
13 * The units digit of a number is the rightmost digit of the number.
14 *
15 *
16 * Example 1:
17 *
18 * Input: num = 58, k = 9
19 * Output: 2
20 * Explanation:
21 * One valid set is [9,49], as the sum is 58 and each integer has a units digit of 9.
22 * Another valid set is [19,39].
23 * It can be shown that 2 is the minimum possible size of a valid set.
24 *
25 * Example 2:
26 *
27 * Input: num = 37, k = 2
28 * Output: -1
29 * Explanation: It is not possible to obtain a sum of 37 using only integers that have a units digit of 2.
30 *
31 * Example 3:
32 *
33 * Input: num = 0, k = 7
34 * Output: 0
35 * Explanation: The sum of an empty set is considered 0.
36 *
37 *
38 * Constraints:
39 *
40 * 0 <= num <= 3000
41 * 0 <= k <= 9
42 *
43 */
44pub struct Solution {}
45
46// problem: https://leetcode.com/problems/sum-of-numbers-with-units-digit-k/
47// discuss: https://leetcode.com/problems/sum-of-numbers-with-units-digit-k/discuss/?currentPage=1&orderBy=most_votes&query=
48
49// submission codes start here
50
51impl Solution {
52 pub fn minimum_numbers(num: i32, k: i32) -> i32 {
53 0
54 }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61 use super::*;
62
63 #[test]
64 fn test_2310() {
65 }
66}
67
Back
© 2025 bowen.ge All Rights Reserved.