给定一个整型数组, 你的任务是找到所有该数组的递增子序列,递增子序列的长度至少是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 递增子序列的更多相关文章

  1. [LeetCode] 491. Increasing Subsequences 递增子序列

    Given an integer array, your task is to find all the different possible increasing subsequences of t ...

  2. [LeetCode] Increasing Subsequences 递增子序列

    Given an integer array, your task is to find all the different possible increasing subsequences of t ...

  3. 【LeetCode】491. Increasing Subsequences 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  4. 491. Increasing Subsequences增长型序列

    [抄题]: Given an integer array, your task is to find all the different possible increasing subsequence ...

  5. LeetCode 491. Increasing Subsequences

    原题链接在这里:https://leetcode.com/problems/increasing-subsequences/ 题目: Given an integer array, your task ...

  6. 491. Increasing Subsequences

    这种increasing xxx 题真是老客户了.. 本题麻烦点在于不能重复, 但是和之前的那些 x sum的题目区别在于不能排序的 所以.... 我还是没搞定. 看了一个Java的思路是直接用set ...

  7. 【leetcode】491. Increasing Subsequences

    题目如下: 解题思路:这题把我折腾了很久,一直没找到很合适的方法,主要是因为有重复的数字导致结果会有重复.最后尝试用字典记录满足条件的序列,保证不重复,居然Accept了. 代码如下: class S ...

  8. Leetcode之深度优先搜索&回溯专题-491. 递增子序列(Increasing Subsequences)

    Leetcode之深度优先搜索&回溯专题-491. 递增子序列(Increasing Subsequences) 深度优先搜索的解题详细介绍,点击 给定一个整型数组, 你的任务是找到所有该数组 ...

  9. [Swift]LeetCode491. 递增子序列 | Increasing Subsequences

    Given an integer array, your task is to find all the different possible increasing subsequences of t ...

随机推荐

  1. UI UISearchBar UISearchDisplayController实现搜索条、解析颜色

    本文转载至 http://blog.sina.com.cn/s/blog_bf2d33bd01017q6l.html @interface ThirdViewController : UIViewCo ...

  2. junit使用小结

    1.spring中使用 @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes=CDPlayerConfig.cla ...

  3. myeclipse -vmargs -Xmx512m -XX:MaxPermSize=256m -XX:ReservedCodeCacheSize=64m

    myeclipse.ini把里面的参数为 -vmargs -Xmx512m -XX:MaxPermSize=256m -XX:ReservedCodeCacheSize=64m 以对于我而言,我只要把 ...

  4. Delphi服务端和PHP客户端通过Socket通信

    在开始之前看下效果 PHP页面作为客户端发送请求给作为服务端的Delphi应用程序 PHP客户端页面打开如下 Delphi服务端应用程序打开如下 每次PHP页面刷新一下,Delphi的文本框都显示&q ...

  5. (linux)wake_lock机制

      Android的休眠唤醒主要基于wake_lock机制,只要系统中存在任一有效的wake_lock,系统就不能进入深度休眠,但可以进行设备的浅度休眠操作.wake_lock一般在关闭lcd.tp但 ...

  6. 如何查看一个Application是32位的还是64位的?

    使用process explorer查看,找到对应的进程. 注册表的路径是Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ 使用powershell查 ...

  7. 获取cookie值

    function get_cookie(Name) { var search = Name + "=" var returnvalue = ""; if (do ...

  8. dba操作之archivelog清理

    下面的命令用于校验归档日志的有效性,列出无效的归档日志,以及以何种方式清除归档日志,列出几种常用的: crosscheck archivelog all;                        ...

  9. java socket 以及 流 关闭的问题

    首先我一下几个提出问题:稍后再做出解答. 问题一:A如果仅仅将输入流关闭(inA.close()),对A与B之间的连接是否有影响? A能否再次获得输入流(inA = socketA.getInputS ...

  10. SPOJ:K-Query Online(归并树)

    Given a sequence of n numbers a1, a2, ..., an and a number of k-queries. A k-query is a triple (i, j ...