Created
October 23, 2018 04:29
-
-
Save tech-cow/68b4302ee131b5714f076dddefc3d50a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution: | |
| def subsets(self, nums): | |
| if not nums: return [] | |
| self.res = [] | |
| self.dfs(nums, [], 0) | |
| return self.res | |
| def dfs(self, nums, temp, index): | |
| if index == len(nums): | |
| self.res.append(temp[:]) | |
| return | |
| # Case 1: Add number into temp array | |
| temp.append(nums[index]) | |
| self.dfs(nums, temp, index + 1) | |
| temp.pop() | |
| # Case 2: Add Nothing | |
| self.dfs(nums, temp, index + 1) | |
| class Solution(object): | |
| def subsets(self, nums): | |
| if not nums: return [] | |
| self.res = [] | |
| self.dfs(nums, 0, []) | |
| return self.res | |
| def dfs(self, nums, start, temp): | |
| self.res.append(temp[:]) | |
| for i in range(start, len(nums)): | |
| temp.append(nums[i]) | |
| self.dfs(nums, i + 1, temp) | |
| temp.pop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment