491 Increasing Subsequences 递增子序列
给定一个整型数组, 你的任务是找到所有该数组的递增子序列,递增子序列的长度至少是2。
示例:
输入: [4, 6, 7, 7]
输出: [[4, 6], [4, 7], [4, 6, 7], [4, 6, 7, 7], [6, 7], [6, 7, 7], [7,7], [4,7,7]]
说明:
1.给定数组的长度不会超过15。
2.数组中的整数范围是 [-100,100]。
3.给定数组中可能包含重复数字,相等的数字应该被视为递增的一种情况。
详见:https://leetcode.com/problems/increasing-subsequences/description/
C++:
class Solution {
public:
vector<vector<int>> findSubsequences(vector<int>& nums)
{
set<vector<int>> res;
vector<vector<int>> cur(1);
for (int i = 0; i < nums.size(); ++i)
{
int n = cur.size();
for (int j = 0; j < n; ++j)
{
if (!cur[j].empty() && cur[j].back() > nums[i])
{
continue;
}
cur.push_back(cur[j]);
cur.back().push_back(nums[i]);
if (cur.back().size() >= 2)
{
res.insert(cur.back());
}
}
}
return vector<vector<int>>(res.begin(), res.end());
}
};
参考:http://www.cnblogs.com/grandyang/p/6388103.html
491 Increasing Subsequences 递增子序列的更多相关文章
- [LeetCode] 491. Increasing Subsequences 递增子序列
Given an integer array, your task is to find all the different possible increasing subsequences of t ...
- [LeetCode] Increasing Subsequences 递增子序列
Given an integer array, your task is to find all the different possible increasing subsequences of t ...
- 【LeetCode】491. Increasing Subsequences 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 491. Increasing Subsequences增长型序列
[抄题]: Given an integer array, your task is to find all the different possible increasing subsequence ...
- LeetCode 491. Increasing Subsequences
原题链接在这里:https://leetcode.com/problems/increasing-subsequences/ 题目: Given an integer array, your task ...
- 491. Increasing Subsequences
这种increasing xxx 题真是老客户了.. 本题麻烦点在于不能重复, 但是和之前的那些 x sum的题目区别在于不能排序的 所以.... 我还是没搞定. 看了一个Java的思路是直接用set ...
- 【leetcode】491. Increasing Subsequences
题目如下: 解题思路:这题把我折腾了很久,一直没找到很合适的方法,主要是因为有重复的数字导致结果会有重复.最后尝试用字典记录满足条件的序列,保证不重复,居然Accept了. 代码如下: class S ...
- Leetcode之深度优先搜索&回溯专题-491. 递增子序列(Increasing Subsequences)
Leetcode之深度优先搜索&回溯专题-491. 递增子序列(Increasing Subsequences) 深度优先搜索的解题详细介绍,点击 给定一个整型数组, 你的任务是找到所有该数组 ...
- [Swift]LeetCode491. 递增子序列 | Increasing Subsequences
Given an integer array, your task is to find all the different possible increasing subsequences of t ...
随机推荐
- Java实现HttpClient发送GET、POST请求(https、http)
1.引入相关依赖包 jar包下载:httpcore4.5.5.jar fastjson-1.2.47.jar maven: <dependency> <groupId>o ...
- HDU 6096 String 排序 + 线段树 + 扫描线
String Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others) Problem De ...
- jvm 调优(2)垃圾回收算法
可以从不同的的角度去划分垃圾回收算法: 按照基本回收策略分 引用计数(Reference Counting): 比较古老的回收算法.原理是此对象有一个引用,即增加一个计数,删除一个引用则减少一个计数. ...
- java 提高效率的做法
可供程序利用的资源(内存.CPU时间.网络带宽等)是有限的,优化的目的就是让程序用尽可能少的资源完成预定的任务.优化通常包含两方面的内容:减小代码的体积,提高代码的运行效率.本文讨论的主要是如何提高代 ...
- gitlab merge过程
基本步骤如下: 以我的分支为例 1.创建本地分支,命令 git checkout -b liuping_develop2.创建好分支后提交到远程 ,命令 git push origin liuping ...
- JavaScript and ActionScript3
接触JavaScript和ActionScript3也有一段时间了,它们都是应用比较广泛的脚本语言,经过这几年的工作和学习,静下来的时候想总结一些东西,作为技术上的沉淀以及培训所用,所以就有了这篇文章 ...
- 使用zxing编写的二维码生成解析工具:QRCoder
zxing GitHub地址 QRCoder GitHub地址 TipDialog.java package com.wolf_pan; import java.util.Timer; import ...
- spring中PropertyPlaceholderHelper替换占位符的值
1.Properties中的值替换¥{}或者#{}占位符 String text = "foo=${foo},bar=${bar}"; Properties props = new ...
- [Selenium] Android 中旋转屏幕,触摸,滚动
package com.learingselenium.android; import junit.framework.TestCase import org.openqa.selenium.Rota ...
- kali-linux简单学习
一. curl --head 返回操作系统的版本 同样的Xprobe2可以和nmap一起返回操作系统的版本 nmap 直接加域名或者ip地址,比较权威判断操作系统版本,或者服务版本,以及开的端口 nm ...