题目如下:

解题思路:这题把我折腾了很久,一直没找到很合适的方法,主要是因为有重复的数字导致结果会有重复。最后尝试用字典记录满足条件的序列,保证不重复,居然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. Scratch少儿编程系列:(四)脚本选项卡说明

    脚本选项卡下面主要包括:运动.事件.外观.控制.声音.侦测.画笔.运算.数据.更多积木. 一.运动:所谓运动,指的是角色的“运动”.如移动10步,右转15度,左转15度等. [注] 将“脚本”从选项卡 ...

  2. Java多线程学习——sleep和yield

    Thread.sleep(); Thread.yield(); 相同点: 让线程暂停运行. 都是静态方法,可以直接调用. 不同点: sleep让线程从运行状态进入阻塞状态,但是不放开手中的资源. yi ...

  3. input标签内容改变时触发事件

    1. onchange事件与onpropertychange事件的区别: onchange事件在内容改变(两次内容有可能相等)且失去焦点时触发: onpropertychange事件是实时触发,每增加 ...

  4. 关于migration build failed的问题

    首先一定要执行dotnet restore 查看网站的依赖关系(有时候生成是不报错的但是restore会找不到文件路径) 检查执行命令的路径是否是正确的当前网站路径 build failed一定是生成 ...

  5. Deepin15.10 python3安装、更新pip

    Deepin自带的Python3没有pip 需要安装一下: sudo apt install python3-pip更新pip sudo pip3 install --upgrade pip 然后运行 ...

  6. P2010回文日期

    这道题是2016年普及组的题,难度等级为普及-. 这道题仍然是个模拟题.有两种策略:1.枚举回文,看日期是否存在2.枚举日期,看是否是回文.显然,前者要快很多,并且准确.本蒟蒻第一次便使用了后者,bu ...

  7. ubuntu 配置 tftp 服务器

    一. 安装 tftp 1.1. 安装 tftp 所需的软件. a. 安装 tftp-hpa,tftpd-hpa,前者是客户端,后者是服务程序, 在终端下输入 sudo apt-get install ...

  8. [多校联考2019(Round 4 T2)][51nod 1288]汽油补给(ST表+单调栈)

    [51nod 1288]汽油补给(ST表+单调栈) 题面 有(N+1)个城市,0是起点N是终点,开车从0 -> 1 - > 2...... -> N,车每走1个单位距离消耗1个单位的 ...

  9. bootstrap使用总结(carousel设置大小。item设置大小,img设置大小)

    在bootstrap中使用carousel,先要给.carousel一个大小, 要想使carousel和item和img随着浏览器大小而变,就要设置 .carousel .item { height: ...

  10. 排列perm HYSBZ - 1072(状压dp/暴力)

    Description 给一个数字串s和正整数d, 统计s有多少种不同的排列能被d整除(可以有前导0).例如123434有90种排列能被2整除,其中末位为2的有30种,末位为4的有60种. Input ...