java.lang.Object
g2501_2600.s2597_the_number_of_beautiful_subsets.Solution

public class Solution extends Object
2597 - The Number of Beautiful Subsets.<p>Medium</p> <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p> <p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p> <p>Return <em>the number of <strong>non-empty beautiful</strong> subsets of the array</em> <code>nums</code>.</p> <p>A <strong>subset</strong> of <code>nums</code> is an array that can be obtained by deleting some (possibly none) elements from <code>nums</code>. Two subsets are different if and only if the chosen indices to delete are different.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [2,4,6], k = 2</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong></p> <p>The beautiful subsets of the array nums are: [2], [4], [6], [2, 6].</p> <p>It can be proved that there are only 4 beautiful subsets in the array [2,4,6].</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [1], k = 1</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong></p> <p>The beautiful subset of the array nums is [1].</p> <p>It can be proved that there is only 1 beautiful subset in the array [1].</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 20</code></li> <li><code>1 <= nums[i], k <= 1000</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • beautifulSubsets

      public int beautifulSubsets(int[] nums, int k)