Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion problems/0078.子集.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,10 @@ public:

## 其他语言版本


### Java

回溯(版本一)

```java
class Solution {
List<List<Integer>> result = new ArrayList<>();// 存放符合条件结果的集合
Expand All @@ -201,7 +203,39 @@ class Solution {
}
```

回溯(版本二)

```java
/**
* 存取法
* 参考高中组合的思路,抽象为二叉树
*/
class Solution {
private List<List<Integer>> result = new ArrayList<>();
private Deque<Integer> path = new LinkedList<>();

public List<List<Integer>> subsets(int[] nums) {
backtracking(nums, 0);
return result;
}

public void backtracking(int[] nums, int startIndex) {
if (startIndex >= nums.length) {
result.add(new ArrayList(path));
return;
}
// 不放入回溯
backtracking(nums, startIndex + 1);
// 放入回溯
path.offerLast(nums[startIndex]);
backtracking(nums, startIndex + 1);
path.pollLast();
}
}
```

### Python

```python
class Solution:
def subsets(self, nums):
Expand Down