2719. Count of Integers Hard
1/**
2 * [2719] Count of Integers
3 *
4 * You are given two numeric strings num1 and num2 and two integers max_sum and min_sum. We denote an integer x to be good if:
5 *
6 * num1 <= x <= num2
7 * min_sum <= digit_sum(x) <= max_sum.
8 *
9 * Return the number of good integers. Since the answer may be large, return it modulo 10^9 + 7.
10 * Note that digit_sum(x) denotes the sum of the digits of x.
11 *
12 * <strong class="example">Example 1:
13 *
14 * Input: num1 = "1", num2 = "12", min_sum = 1, max_sum = 8
15 * Output: 11
16 * Explanation: There are 11 integers whose sum of digits lies between 1 and 8 are 1,2,3,4,5,6,7,8,10,11, and 12. Thus, we return 11.
17 *
18 * <strong class="example">Example 2:
19 *
20 * Input: num1 = "1", num2 = "5", min_sum = 1, max_sum = 5
21 * Output: 5
22 * Explanation: The 5 integers whose sum of digits lies between 1 and 5 are 1,2,3,4, and 5. Thus, we return 5.
23 *
24 *
25 * Constraints:
26 *
27 * 1 <= num1 <= num2 <= 10^22
28 * 1 <= min_sum <= max_sum <= 400
29 *
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/count-of-integers/
34// discuss: https://leetcode.com/problems/count-of-integers/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39 pub fn count(num1: String, num2: String, min_sum: i32, max_sum: i32) -> i32 {
40 0
41 }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn test_2719() {
52 }
53}
54
Back
© 2025 bowen.ge All Rights Reserved.