【LeetCode】491.Increasing Subsequences(Medium)解题报告
来源:互联网 发布:思迅会计软件 编辑:程序博客网 时间:2024/05/18 12:37
【LeetCode】491.Increasing Subsequences(Medium)解题报告
题目地址:https://leetcode.com/problems/increasing-subsequences/description/
题目描述:
Given an integer array, your task is to find all the different possible increasing subsequences of the given array, and the length of an increasing subsequence should be at least 2 .
Example:Input: [4, 6, 7, 7]Output: [[4, 6], [4, 7], [4, 6, 7], [4, 6, 7, 7], [6, 7], [6, 7, 7], [7,7], [4,7,7]]
Note:1. The length of the given array will not exceed 15.2. The range of integer in the given array is [-100,100].3. The given array may contain duplicates, and two equal integers should also be considered as a special case of increasing sequence.
本题涉及到组合,但是有额外三个要求,每个组合多于一个元素,不重复(set解决),递增。做本题前最好先做下基本的组合的题目。
Solution:
class Solution { public List<List<Integer>> findSubsequences(int[] nums) { Set<List<Integer>> set = new HashSet<>(); findSub(set,nums,new ArrayList<>(),0); return new ArrayList<>(set); } public void findSub(Set<List<Integer>> set, int[] nums , List<Integer> tempList,int index){ if(tempList.size()>1){ set.add(new ArrayList<>(tempList)); } for(int i=index ; i<nums.length ; i++){ if(tempList.size()==0 || tempList.get(tempList.size()-1)<=nums[i]){ tempList.add(nums[i]); findSub(set,nums,tempList,i+1); tempList.remove(tempList.size() - 1); } } }}
Date:2017年11月27日
阅读全文
0 0
- 【LeetCode】491.Increasing Subsequences(Medium)解题报告
- [Leetcode] 491. Increasing Subsequences 解题报告
- Leetcode 491. Increasing Subsequences 上升序列 解题报告
- 【LeetCode】 491. Increasing Subsequences
- LeetCode 491. Increasing Subsequences
- LeetCode 491. Increasing Subsequences
- [LeetCode]491. Increasing Subsequences
- [leetcode]491. Increasing Subsequences
- 【Leetcode】491. Increasing Subsequences
- [leetcode] 491. Increasing Subsequences
- Leetcode -- 491. Increasing Subsequences
- leetcode-491. Increasing Subsequences
- (LeetCode) 491. Increasing Subsequences
- LeetCode 491. Increasing Subsequences
- Leetcode-491. Increasing Subsequences
- leetcode 491. Increasing Subsequences
- LeetCode-491. Increasing Subsequences
- LeetCode 491. Increasing Subsequences
- 显示中文
- vue快速入门的三个小实例
- MongoDB在windows 64下的安装方法
- Uva11987 Almost Union-Find 并查集带删除
- Could not create the view: An unexpected exception was thrown的解决方法
- 【LeetCode】491.Increasing Subsequences(Medium)解题报告
- hiho1515(加权并查集经典题)
- Hibernate中的事务
- 机器学习实战——Logistic回归
- Windows常用操作
- 【学习C++】学习C++ -> 选择结构程序设计
- python模块及安装学习
- 蓝桥杯-最大最小公倍数
- DEDECMS后台无法登陆并跳转回登陆界面的解决方法