求集合不重复的子集:

下面python的写法很好啊!

class Solution(object):
def subsets(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
res = [[]]
for num in nums :
for temp in res[:] :
x = temp[:]
x.append(num)
res.append(x)
return res
if __name__ == '__main__':
x=Solution()
res = x.subsets({1,2,3})
for r in res:
print(r)

其他的详细参考:https://blog.csdn.net/happyaaaaaaaaaaa/article/details/51604217

【medium】78. Subsets的更多相关文章

  1. 【LeetCode】78. Subsets (2 solutions)

    Subsets Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset ...

  2. 【LeetCode】78. Subsets 解题报告(Python & C++)

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

  3. 【LeetCode】90. Subsets II 解题报告(Python & C++)

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

  4. 【CF660E】Different Subsets For All Tuples 结论题

    [CF660E]Different Subsets For All Tuples 题意:对于所有长度为n,每个数为1,2...m的序列,求出每个序列的本质不同的子序列的数目之和.(多个原序列可以有相同 ...

  5. 2. Add Two Numbers【medium】

    2. Add Two Numbers[medium] You are given two non-empty linked lists representing two non-negative in ...

  6. 92. Reverse Linked List II【Medium】

    92. Reverse Linked List II[Medium] Reverse a linked list from position m to n. Do it in-place and in ...

  7. 82. Remove Duplicates from Sorted List II【Medium】

    82. Remove Duplicates from Sorted List II[Medium] Given a sorted linked list, delete all nodes that ...

  8. 61. Search for a Range【medium】

    61. Search for a Range[medium] Given a sorted array of n integers, find the starting and ending posi ...

  9. 62. Search in Rotated Sorted Array【medium】

    62. Search in Rotated Sorted Array[medium] Suppose a sorted array is rotated at some pivot unknown t ...

随机推荐

  1. 【转】Linux中的特殊权限粘滞位(sticky bit)详解

    Linux下的文件权限 在linux下每一个文件和目录都有自己的访问权限,访问权限确定了用户能否访问文件或者目录和怎样进行访问.最为我们熟知的一个文件或目录可能拥有三种权限,分别是读.写.和执行操作, ...

  2. 清北学堂(2019 4 28 ) part 1

    今天主要用来铺路,打基础 枚举 没什么具体算法讲究,但要考虑更优的暴力枚举方法,例如回文质数,有以下几种思路: 1.挨个枚举自然数,再一起判断是否是回文数和质数,然而一看就不是最优 2.先枚举质数再判 ...

  3. C#中声明、调用和配置事件的演示源码

    下面的内容是关于C#中声明.调用和配置事件的演示的内容,应该能对大伙有些好处. using System;namespace MyCollections { using System.Collecti ...

  4. 调试ucosii_pendsv中断函数有感

    发现自己的代码的意思和自己理解的意思有不相同的时候,自己先用printf打印输出分析 当发现是自己那一个知识点没有掌握好时,自己用其他的C编译器,仿写用到的知识点的程序,然后掌握该知识点. 最后实在找 ...

  5. P1536 村村通

    原题链接 https://www.luogu.org/problemnew/show/P1536 昨天刚学的并查集,今天正好练习一下,于是就找到了这个题 看起来好像很简单,尤其是你明白了思路之后,完全 ...

  6. App自动化(1)--Appium-Android环境搭建

    本次笔记记录Appium-Android环境搭建,主要实现在windows上通过python编写脚本来实现模拟器上安装的app自动化测试. 主要步骤:安装node.js,配置JDK环境,配置Andro ...

  7. bzoj3678 Katu Puzzle

    题目链接 题意 给定一张图,对于每条边给出一个运算符\((\&,|,\otimes)\)和一个值\(c(0 \le c \le 1)\).问能否通过给每个点赋上一个值.使得每条边通过指定的运算 ...

  8. cocos2d windows游戏平台搭建

    1. 安装VS2013 2. 下载cocos2d源代码(cocos2d-x-3.7.1) 3. 下载和安装python(2.7.10) 4. 安装完成后,将python安装路径设置到系统路径中(pat ...

  9. openvpn搭建

    以ubuntu系统为例: 1.安装openvpn和easy-rsa,easy-rsa主要用来设置CA(证书颁发机构) $ sudo apt-get update $ sudo apt-get inst ...

  10. SNMP mib文件说明

    MIB file的开始和结束 所有的MIB file的都以DEFINITIONS ::= BEGIN关键字开始,以END结束.我们所有添加的节点均应在此之间. XXX-TEST-MIB DEFINIT ...