Leetcode no. 90
来源:互联网 发布:财务软件 知乎 编辑:程序博客网 时间:2024/04/28 20:52
90. Subsets II
Given a collection of integers that might contain duplicates, nums, return all possible subsets.
Note:
- Elements in a subset must be in non-descending order.
- The solution set must not contain duplicate subsets.
For example,
If nums = [1,2,2]
, a solution is:
[ [2], [1], [1,2,2], [2,2], [1,2], []]
public class Solution { public List<List<Integer>> subsetsWithDup(int[] nums) { List<List<Integer>> list= new LinkedList<>(); list.add(new LinkedList<>()); if (nums.length==0) return list; Arrays.sort(nums); int prev= nums[0], count=1; List<List<Integer>> previous= new LinkedList<>(list); for (int i = 0; i < nums.length; i++) { List<List<Integer>> sublist= new LinkedList<>(); if (i>0 && nums[i] == prev) { count++; for (List<Integer> ele: previous) { List<Integer> tmp = new LinkedList<>(ele); for (int j = 0; j < count; j++) { tmp.add(nums[i]); } sublist.add(tmp); } } else { for (List<Integer> ele : list) { List<Integer> tmp = new LinkedList<>(ele); tmp.add(nums[i]); sublist.add(tmp); count = 1; prev= nums[i]; previous= new LinkedList<>(list); } } list.addAll(sublist); } return list; }}
0 0
- Leetcode no. 90
- Leetcode NO.90 Subsets II
- LeetCode No.90 Subsets II
- LeetCode No.11 ~No.12
- Leetcode NO.78 Subsets
- Leetcode NO.77 Combinations
- Leetcode NO.46 Permutations
- 【leetcode】No. 235 LCABST
- LeetCode no. 35
- Leetcode no. 37
- Leetcode no. 279
- Leetcode no. 335
- Leetcode no. 283
- Leetcode no. 181 (sql)
- Leetcode no. 40
- Leetcode no. 238
- Leetcode no. 26
- Leetcode no. 80
- linux 删除共享内存段
- JUC源码分析5-locks-LockSupport
- php使用json_decode返回NULL
- ExtJS -- QuickTip grid设置鼠标移动到行时提示第一列的信息
- 国内技术团队博客
- Leetcode no. 90
- 7walker闪屏
- PullToRefresh上拉加载,下拉刷新
- 347. Top K Frequent Elements (C++程序实现,两种方案)
- C# ListView 编写 ListView 实体类
- Unicode char*转化为LPCTSTR
- pyftpdlib代码初印象
- apk的反编译
- 把tomcat加入到windows服务