| [ Web Proxy ] |
| Viewing: https://raw.githubusercontent.com/Monika-R/LeetCode-Solutions/master/Python/subsets.py | [Back] [Original] |
# Time: O(n * 2^n)
# Space: O(1)
class Solution(object):
def subsets(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
nums.sort()
result = [[]]
for i in xrange(len(nums)):
size = len(result)
for j in xrange(size):
result.append(list(result[j]))
result[-1].append(nums[i])
return result
# Time: O(n * 2^n)
# Space: O(1)
class Solution2(object):
def subsets(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
result = []
i, count = 0, 1
| Web Proxy Viewer | New URL | Original Page |