求集合不重复的子集:

下面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. 关联分析中寻找频繁项集的FP-growth方法

    关联分析是数据挖掘中常用的分析方法.一个常见的需求比如说寻找出经常一起出现的项目集合. 引入一个定义,项集的支持度(support),是指所有包含这个项集的集合在所有数据集中出现的比例. 规定一个最小 ...

  2. Appium 服务器初始化参数(Capability)

    键 描述 值 automationName 自动化测试的引擎 Appium (默认)或者 Selendroid platformName 使用的手机操作系统 iOS, Android, 或者 Fire ...

  3. [转帖]Windows Server 2016各种版本介绍

    Windows Server 2016各种版本介绍 http://www.5sharing.com/js/zx/872.html windows server的版本 时间:2018-10-06 10: ...

  4. 如何在springboot项目中进行XSS过滤

    简单介绍 XSS : 跨站脚本攻击(Cross Site Scripting),为不和层叠样式表(Cascading Style Sheets, CSS)的缩写混淆,故将跨站脚本攻击缩写为XSS.恶意 ...

  5. 定时任务调度工作(学习记录 二)timer定时函数的用法

    schedule的四种用法: 1.schedule(task,time) 参数: task----所安排的任务 time----执行任务的时间 作用: 在时间等于或超过time的时候执行且仅执行一次t ...

  6. ElasticSearch搜索(一)

    首先从ES的支持的字段说起,ES文档中字段有多种类型 官方文档. 这几个比较常用: text,keyword,integer,float,boolean,object,geo_point(地理坐标), ...

  7. Luogu4492 [HAOI2018]苹果树 【动态规划】

    题目分析: 思路不难想,考虑三个dp状态$f,g,d$. $g[i]$表示有$i$个点的堆的数量 $d[i]$表示有$i$个点的情况下所有的方案数中点到根的距离和 $f[i]$表示要求的答案. 不难发 ...

  8. Springboot文件上传与下载

    一.创建简单的springboot-web项目 二.文件上传属性配置 #默认支持文件上传 spring.http.multipart.enabled =true spring.http.multipa ...

  9. echart在X轴下方添加字

    使用Echart做统计图表,这个方便快捷还高大上 官方网址 https://www.echartsjs.com/ 按照文档,很快就做出了一个柱图表 在X轴下方,要显示出对应日期是星期几(上图最下方,用 ...

  10. .Net Core实践3 配置文件

    环境 .netcore2.1 / vs2017 / win10 / centos7 在.netcore项目中读取配置文件,先添加应用程序配置文件App.config.这个是类库项目的配置文件名. Sy ...