题目如下:

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

代码如下:

class Solution(object):
def findSubsequences(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
res = []
queue = []
dic = {}
for i in range(len(nums)):
#pair = Pair([nums[i]], [i])
queue.append(([nums[i]], i))
# print queue dic = {} while len(queue) > 0:
nl,inx = queue.pop(0)
if len(nl) > 1:
s = ''
for i in nl:
s += str(i)
s += ','
s = s[:-1]
if s not in dic:
dic[s] = 1
#res.append(s)
for i in range(inx+1,len(nums)):
if nl[-1] <= nums[i]:
queue.append((nl + [nums[i]], i))
for i in dic.iterkeys():
rl = i.split(',')
rl2 = []
for i in rl:
rl2.append(int(i))
res.append(rl2)
return (res)

【leetcode】491. Increasing Subsequences的更多相关文章

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

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

  2. 【LeetCode】334. Increasing Triplet Subsequence 解题报告(Python)

    [LeetCode]334. Increasing Triplet Subsequence 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode. ...

  3. 【LeetCode】115. Distinct Subsequences 解题报告(Python)

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

  4. 【LeetCode】940. Distinct Subsequences II 解题报告(Python)

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

  5. 【LeetCode】114. Distinct Subsequences

    Distinct Subsequences Given a string S and a string T, count the number of distinct subsequences of  ...

  6. 【Leetcode】115. Distinct Subsequences

    Description: Given two string S and T, you need to count the number of T's subsequences appeared in ...

  7. 【leetcode】Monotone Increasing Digits

    Given a non-negative integer N, find the largest number that is less than or equal to N with monoton ...

  8. 【leetcode】940. Distinct Subsequences II

    题目如下: Given a string S, count the number of distinct, non-empty subsequences of S . Since the result ...

  9. 【LeetCode】897. Increasing Order Search Tree 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 重建二叉树 数组保存节点 中序遍历时修改指针 参考资 ...

随机推荐

  1. 操作系统(1)——X86-32硬件介绍、实验环境相关配置、uCore部分技巧介绍

    实验环境 本文假设已经创建虚拟机并配置好Ubuntu 16.04(网上太多教程了,所以这里就不赘述了). X86-32硬件介绍 x86指的是80386这种机器(一种32位CPU,在早期得到了广泛的应用 ...

  2. idea的掌握

    1:idea的界面了解(一般都会勾选这两项,编码比较方便) 2: 如何配置sdk(jdk,最后一个生成的是.class文件的位置) 3: 如何单个项目配置和全局配置 4:如何配置项目的jdk编译版本和 ...

  3. hdu5993/2016icpc青岛L

    zz:https://www.cnblogs.com/ytytzzz/p/9674661.html 题意:给一棵树,每次询问删掉两条边,问剩下的三棵树的最大直径点10W,询问10W,询问相互独立 So ...

  4. 根据对象属性查找对象或者数组(根据对象属性查找某数组内符合该条件的对象,数组内对象属性check为true的对象,存放到数组内) 滚动轴样式

      1.根据对象属性查找某数组内符合该条件的对象. optionComwords:[ {optionName:"名称1", optionCode: '1'}, {optionNam ...

  5. 红帽学习笔记[RHCSA] 第四课[用户相关、破解root密码]

    第四课 关于Linux 的用户 用户分类: # UID 是用户ID ​ UID 0分配给超级用户(root) ​ UID 1-200 是一系列的 系统用户 静态分配给红帽的系统进程 ​ UID 201 ...

  6. 杭州集训Day4

    别问我为什么没有前三天,有时间再补~ 60+60+50=170. T1 . 坐等 memset0 ( 1s 256MB )( 原题:洛谷CF1151E Number of Components ) 树 ...

  7. [2019沈阳网络赛D题]Dawn-K's water(点分治)

    题目链接 题意为求出树上任意点对的距离对3取余的和. 比赛上听到题意就知道是点分治了,但是越写越不对劲,交之前就觉得会T,果不其然T了.修修改改结果队友写了发dp直接就过了Orz. 赛后想了想维护的东 ...

  8. [BZOJ 3456]城市规划(cdq分治+FFT)

    [BZOJ 3456]城市规划(cdq分治+FFT) 题面 求有标号n个点无向连通图数目. 分析 设\(f(i)\)表示\(i\)个点组成的无向连通图数量,\(g(i)\)表示\(i\)个点的图的数量 ...

  9. JDBC插入中文数据出现?号地解决问题

    1. 查看jdbc配置是否指定编码 Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/te ...

  10. Dire Wolf——HDU5115(区间DP)

    题意 就是有一对狼,每个狼有初始的攻击力,并且还能给左右两边的狼提供攻击力加成,当冒险家杀死一头狼的时候他也会受到这个狼目前攻击力的伤害 实例解析 33 5 78 2 0 有三头狼,刚开始第二头狼给他 ...