Leetcode 78. Subsets
2016-01-23 14:37
399 查看
Given a set of distinct integers, nums,
return all possible subsets.
Analysis, just to use the former result and then add some elements to the result set.
在CC150 中这道题被称为Dynamic programming, I think so , because it uses the result from the last step and add a new element to the last result
to get the new result.
return all possible subsets.
Analysis, just to use the former result and then add some elements to the result set.
在CC150 中这道题被称为Dynamic programming, I think so , because it uses the result from the last step and add a new element to the last result
to get the new result.
public class Solution { public List<List<Integer>> subsets(int[] nums) { List<List<Integer>> result = new ArrayList<List<Integer>>(); int length = nums.length; if(length <= 0) return result; Arrays.sort(nums); List<Integer> tem = new ArrayList<Integer>(); result.add(tem); for(int i = 0; i < length; i++){ int size = result.size(); for(int j = 0; j < size; j++){ List<Integer> newone = new ArrayList(result.get(j)); newone.add(nums[i]); result.add(newone); } } return result; } }
相关文章推荐
- 解释抽象类继承实体类的前提是这个实体类必须明确构造函数
- Response对象
- android细节之禁用activity的系统的默认切换效果
- 序列化
- 图片质量压缩 与 图片格式 JPEG PNG
- HDOJ 2034 人见人爱A-B
- Android多种方法获取系统时间
- [leetcode] 240. Search a 2D Matrix II 解题报告
- UI_滑竿,分段控制器
- 融合透明者的传说
- 3.11 Templates --Rendering with Helpers
- 4种动态加载JS的方法
- 蓝桥杯 算法提高 分苹果
- iOS个人整理14-界面间传值:属性传值---代理传值---block传值---单例传值
- 多层引用赋值的一个错误
- zabbix server is not running端口未开启10051
- UI_手势
- 服务器下虚拟机ping 本机
- [Mysql for Excel指南] 第三章 配置
- 欢迎使用CSDN-markdown编辑器