博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode 90: Subsets II
阅读量:6994 次
发布时间:2019-06-27

本文共 901 字,大约阅读时间需要 3 分钟。

class Solution {    public List
> subsetsWithDup(int[] nums) { List
> result = new ArrayList<>(); result.add(new ArrayList<>()); Arrays.sort(nums); int count = 0; for (int i = 0; i < nums.length; i += count) { count = 0; while (count + i < nums.length && nums[count + i] == nums[i]) { count++; } int prevSize = result.size(); for (int j = 0; j < prevSize; j++) { List
newRow = new ArrayList<>(result.get(j)); for (int k = 0; k < count; k++) { newRow.add(nums[i]); result.add(new ArrayList<>(newRow)); } } } return result; }}

 

转载于:https://www.cnblogs.com/shuashuashua/p/7443336.html

你可能感兴趣的文章
the user operation is waiting for building workspace to complete
查看>>
LintCode_14 二分查找
查看>>
04-python3.5-模拟三级菜单-省-县-区域--01
查看>>
算法竞赛入门经典chapter4:本章小结
查看>>
asp.net中的<%%>形式的详细用法实例讲解
查看>>
【LeetCode】3. Longest Substring Without Repeating Characters
查看>>
dao层结构的设计方案
查看>>
(一) 从零开始搭建Spark Standalone集群环境搭建
查看>>
非负矩阵分解(4):NMF算法和聚类算法的联系与区别
查看>>
统计学习方法:核函数(Kernel function)
查看>>
[LeetCode] Minimum Depth of Binary Tree
查看>>
RabbitMQ 之 订阅模式 Publish/Subscribe
查看>>
[jsp学习笔记]servelt get post
查看>>
hibernate的二级缓存----collection和query的二级缓存
查看>>
day6-类的继承
查看>>
Linux SCRT本地免秘钥登录远程机器
查看>>
FLUSH TABLES WITH READ LOCK
查看>>
python异常 Exception
查看>>
转义字符
查看>>
C# SQLiteDataReader获得数据库指定字段的值
查看>>