2597. The Number of Beautiful Subsets
PYTHON3 Solution:\n\nclass Solution:\n    def beautifulSubsets(self, nums: List[int], k: int) -> int:\n        def explore(index):\n            nonlocal count\n
<b>PYTHON3 Solution:</b>\n<hr>\n<pre><div>class Solution:\n    def beautifulSubsets(self, nums: List[int], k: int) -> int:\n        def explore(index):\n            nonlocal count\n            if index == len(nums):\n                count += 1\n                return\n            num = nums[index]\n            if num - k not in visited and num + k not in visited:\n                visited[num] += 1\n                explore(index + 1)\n                visited[num] -= 1\n                if visited[num] == 0:\n                    del visited[num]\n            explore(index + 1)\n\n        count, visited = 0, defaultdict(int)\n        explore(0)\n        return count - 1\n\t\n\t\t\n
['Python']