Subsets
来源:互联网 发布:lg扫地机器人.知乎 编辑:程序博客网 时间:2024/06/05 20:08
Given a set of distinct integers, nums, return all possible subsets.
Note: The solution set must not contain duplicate subsets.
For example,
If nums = [1,2,3]
, a solution is:
[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], []]
Show Similar Problems
普通的dfs题目
代码:
public List<List<Integer>> subsets(int[] nums) { List<List<Integer>> result = new ArrayList<>(); if(nums == null || nums.length == 0) return result; dfs(result, new ArrayList<>(), nums, 0); return result; } private void dfs(List<List<Integer>> result, List<Integer> cur, int[] nums, int index){ if(index == nums.length){ result.add(new ArrayList<>(cur)); return; } result.add(new ArrayList<>(cur)); for(int i=index;i<nums.length;i++){ cur.add(nums[i]); dfs(result, cur, nums, i+1); cur.remove(cur.size()-1); } }
0 0
- Subsets
- Subsets
- Subsets
- Subsets
- Subsets
- Subsets
- Subsets
- Subsets
- Subsets
- Subsets
- Subsets
- Subsets
- Subsets
- Subsets
- Subsets
- Subsets
- Subsets
- Subsets
- HDUoj 2141 Can you find it?(排序+二分)
- Leetcode 106. Construct Binary Tree from Inorder and Postorder Traversal
- Leetcode 272. Closest Binary Search Tree Value II (Hard) (cpp)
- TEC1401.Report开发技术总结 - 第十章 使用BI Publisher开发报表-其他注意事项(5/5)
- Notifycation使用入门
- Subsets
- 【LeetCode】 475. Heaters
- Leetcode 285. Inorder Successor in BST (Medium) (cpp)
- 简单几步实现网络音乐播放器(Python爬虫版百度FM)
- 使用C++扩展Python的功能
- Leetcode 298. Binary Tree Longest Consecutive Sequence (Medium) (cpp)
- Java的堆内存与栈内存的异同(Heap memory vs Stack memory)
- python的未来-pypy
- Leetcode 337. House Robber III (Medium) (cpp)