377. Combination Sum IV Medium

@problem@discussion
#Array#Dynamic Programming



1/**
2 * [377] Combination Sum IV
3 *
4 * Given an array of distinct integers nums and a target integer target, return the number of possible combinations that add up to target.
5 * The test cases are generated so that the answer can fit in a 32-bit integer.
6 *  
7 * Example 1:
8 * 
9 * Input: nums = [1,2,3], target = 4
10 * Output: 7
11 * Explanation:
12 * The possible combination ways are:
13 * (1, 1, 1, 1)
14 * (1, 1, 2)
15 * (1, 2, 1)
16 * (1, 3)
17 * (2, 1, 1)
18 * (2, 2)
19 * (3, 1)
20 * Note that different sequences are counted as different combinations.
21 * 
22 * Example 2:
23 * 
24 * Input: nums = [9], target = 3
25 * Output: 0
26 * 
27 *  
28 * Constraints:
29 * 
30 * 	1 <= nums.length <= 200
31 * 	1 <= nums[i] <= 1000
32 * 	All the elements of nums are unique.
33 * 	1 <= target <= 1000
34 * 
35 *  
36 * Follow up: What if negative numbers are allowed in the given array? How does it change the problem? What limitation we need to add to the question to allow negative numbers?
37 * 
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/combination-sum-iv/
42// discuss: https://leetcode.com/problems/combination-sum-iv/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47    pub fn combination_sum4(nums: Vec<i32>, target: i32) -> i32 {
48        0
49    }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57
58    #[test]
59    fn test_377() {
60    }
61}
62


Back
© 2025 bowen.ge All Rights Reserved.