Time: 44 ms (46.87%), Space: 14.2 MB (33.36%) - LeetHub

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