当前位置:网站首页>面试题 08.04. 幂集
面试题 08.04. 幂集
2022-06-09 12:25:00 【子言慕雨】
题
面试题 08.04. 幂集
幂集。编写一种方法,返回某集合的所有子集。集合中不包含重复的元素。
说明:解集不能包含重复的子集。
示例:
输入: nums = [1,2,3]
输出:
[
[3],
[1],
[2],
[1,2,3],
[1,3],
[2,3],
[1,2],
[]
]
解题思路
算是一种动态规划 用到 以前所有状态数据 注意 Python 复制数组数据要用 .copy()
代码
class Solution:
def subsets(self, nums: List[int]) -> List[List[int]]:
num_now = {
}
ans = [[]]
for data in nums:
if data not in num_now:
num_now[data] = True
size = len(ans)
for i in range(size):
temp = ans[i].copy()
temp.append(data)
ans.append(temp)
return ans
边栏推荐
- 数据库的安装--mysql
- Loki: like Prometheus, but for logs
- 市面常用芯片对应的ARM架构
- 【leetcode周赛记录】第294场周赛记录
- 数据库day-4
- C语言 队列--顺序队列
- Yunna | how to manage fixed assets better? How to manage the company's fixed assets?
- 【C语言练习——打印整数二进制的奇数位和偶数位】
- Fastapi tortoise ORM based on pytest
- Yunna administrative unit fixed assets management system, unit fixed assets management measures
猜你喜欢

市面常用芯片对应的ARM架构

How can PostgreSQL in k8s export query results and import them to the database on the local windows machine

What are the types and aspects of Yunna asset management system

Raspberry Pi树莓派分类和其相似产品介绍

What is the seven layer network structure for? Just read this article

Yunna | what does database monitoring generally monitor

Yunna | how to do a good inventory of fixed assets? How to count fixed assets

【C语言练习——交换两个变量的值】

Event storm method of DDD modeling methodology
![[C language practice - merging two ordered sequences]](/img/9c/30b9440642381e74f21408883780bd.png)
[C language practice - merging two ordered sequences]
随机推荐
【C语言练习——打印整数二进制的奇数位和偶数位】
jstat 详解
C language -- linear list -- double linked list
数字化转型的七个错误认知
记一次程序内存占用高问题排查
[detailed explanation of client list]
Repo 流程
使用nodejs导出md/Markdown文档当中的图片到本地并替换原始图片链接为本地图片链接
What are the characteristics of Bi reporting system
数据库day-1
市面常用芯片对应的ARM架构
C language queue -- chain queue
常见的数据分析误区
How is the Internet topology constructed? What does it represent?
【C语言练习——调整数组内奇数偶数的顺序】
IDEA将现在新增加的修改合并cherry pick到之前的版本
5G发牌三周年 云网融合加速 如何解决企业网络之忧?
Database installation --mysql
C语言队列--链队列
精益产品开发体系最佳实践及原则