2597. The Number of Beautiful Subsets Medium
1/**
2 * [2597] The Number of Beautiful Subsets
3 *
4 * You are given an array nums of positive integers and a positive integer k.
5 * A subset of nums is beautiful if it does not contain two integers with an absolute difference equal to k.
6 * Return the number of non-empty beautiful subsets of the array nums.
7 * A subset of nums is an array that can be obtained by deleting some (possibly none) elements from nums. Two subsets are different if and only if the chosen indices to delete are different.
8 *
9 * <strong class="example">Example 1:
10 *
11 * Input: nums = [2,4,6], k = 2
12 * Output: 4
13 * Explanation: The beautiful subsets of the array nums are: [2], [4], [6], [2, 6].
14 * It can be proved that there are only 4 beautiful subsets in the array [2,4,6].
15 *
16 * <strong class="example">Example 2:
17 *
18 * Input: nums = [1], k = 1
19 * Output: 1
20 * Explanation: The beautiful subset of the array nums is [1].
21 * It can be proved that there is only 1 beautiful subset in the array [1].
22 *
23 *
24 * Constraints:
25 *
26 * 1 <= nums.length <= 20
27 * 1 <= nums[i], k <= 1000
28 *
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/the-number-of-beautiful-subsets/
33// discuss: https://leetcode.com/problems/the-number-of-beautiful-subsets/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38 pub fn beautiful_subsets(nums: Vec<i32>, k: i32) -> i32 {
39 0
40 }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn test_2597() {
51 }
52}
53
Back
© 2025 bowen.ge All Rights Reserved.