Time: 36 ms (77.12%), Space: 14 MB (81.24%) - LeetHub

This commit is contained in:
Deven
2023-01-19 15:39:51 -05:00
parent 6bb384ee00
commit 70bbefa745
+1 -3
View File
@@ -14,9 +14,8 @@ class Solution:
powerSet = [] powerSet = []
for subsetBinary in range(2 ** len(nums)): for subsetBinary in range(2 ** len(nums)):
subset = [nums[i] for i in range(len(nums)) if (((2 ** len(nums) - 1) - (2 ** i)) | subsetBinary == (2 ** len(nums) - 1))] subset = []
"""
# Iterates exactly n times (where n is the number of 1s in the binary string) # Iterates exactly n times (where n is the number of 1s in the binary string)
while subsetBinary > 0: while subsetBinary > 0:
indexOfFirst1 = -(math.floor(math.log2(subsetBinary)) + 1) indexOfFirst1 = -(math.floor(math.log2(subsetBinary)) + 1)
@@ -24,7 +23,6 @@ class Solution:
subset.append(nums[indexOfFirst1]) subset.append(nums[indexOfFirst1])
subsetBinary -= 2 ** (-indexOfFirst1 - 1) subsetBinary -= 2 ** (-indexOfFirst1 - 1)
"""
powerSet.append(subset) powerSet.append(subset)