216. Combination Sum III Medium
1/**
2 * [216] Combination Sum III
3 *
4 * Find all valid combinations of k numbers that sum up to n such that the following conditions are true:
5 *
6 * Only numbers 1 through 9 are used.
7 * Each number is used at most once.
8 *
9 * Return a list of all possible valid combinations. The list must not contain the same combination twice, and the combinations may be returned in any order.
10 *
11 * Example 1:
12 *
13 * Input: k = 3, n = 7
14 * Output: [[1,2,4]]
15 * Explanation:
16 * 1 + 2 + 4 = 7
17 * There are no other valid combinations.
18 * Example 2:
19 *
20 * Input: k = 3, n = 9
21 * Output: [[1,2,6],[1,3,5],[2,3,4]]
22 * Explanation:
23 * 1 + 2 + 6 = 9
24 * 1 + 3 + 5 = 9
25 * 2 + 3 + 4 = 9
26 * There are no other valid combinations.
27 *
28 * Example 3:
29 *
30 * Input: k = 4, n = 1
31 * Output: []
32 * Explanation: There are no valid combinations.
33 * Using 4 different numbers in the range [1,9], the smallest sum we can get is 1+2+3+4 = 10 and since 10 > 1, there are no valid combination.
34 *
35 *
36 * Constraints:
37 *
38 * 2 <= k <= 9
39 * 1 <= n <= 60
40 *
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/combination-sum-iii/
45// discuss: https://leetcode.com/problems/combination-sum-iii/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50 pub fn combination_sum3(k: i32, n: i32) -> Vec<Vec<i32>> {
51 vec![]
52 }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_216() {
63 }
64}
65
Back
© 2025 bowen.ge All Rights Reserved.