当前位置:网站首页>LeetCode 78. 子集
LeetCode 78. 子集
2022-07-02 06:07:00 【大白羊_Aries】
题目描述
解法
在编程中涉及的排列组合问题都离不开回溯,我们下面贴出一个关于回溯的伪代码,有了这个回溯框架,再结合回溯树就很好理解了
result = []
def backtrack(路径, 选择列表):
if 满足结束条件:
result.add(路径)
return
for 选择 in 选择列表:
做选择
backtrack(路径,选择列表)
撤销选择

class Solution {
public:
vector<vector<int>> res;
vector<vector<int>> subsets(vector<int>& nums) {
vector<int> track;
backtrace(nums, 0, track);
return res;
}
void backtrace(vector<int>& nums, int start, vector<int>& track){
res.push_back(track);
for (int i = start; i < nums.size(); i++)
{
track.push_back(nums[i]);
backtrace(nums, i + 1, track);
track.pop_back();
}
}
};
边栏推荐
- Mathematical statistics and machine learning
- Compte à rebours de 3 jours pour l'inscription à l'accélérateur de démarrage Google Sea, Guide de démarrage collecté à l'avance!
- 使用sha256文件验证下载的文件
- Jetpack Compose 与 Material You 常见问题解答
- Zabbix Server trapper 命令注入漏洞 (CVE-2017-2824)
- No subject alternative DNS name matching updates. jenkins. IO found, the reason for the error and how to solve it
- Fundamentals of software testing
- Web page user step-by-step operation guide plug-in driver js
- Google play academy team PK competition, official start!
- Deep learning classification network -- vggnet
猜你喜欢

穀歌出海創業加速器報名倒計時 3 天,創業人闖關指南提前收藏!

Google Play Academy 组队 PK 赛,正式开赛!

Classic literature reading -- deformable Detr

How vite is compatible with lower version browsers

51 single chip microcomputer - ADC explanation (a/d conversion, d/a conversion)

Compte à rebours de 3 jours pour l'inscription à l'accélérateur de démarrage Google Sea, Guide de démarrage collecté à l'avance!

keepalived安装使用与快速入门

Contest3147 - game 38 of 2021 Freshmen's personal training match_ 1: Maximum palindromes

借力 Google Cloud 基础设施和着陆区,构建企业级云原生卓越运营能力

从设计交付到开发,轻松畅快高效率!
随机推荐
Generics and generic constraints of typescript
Google Go to sea entrepreneurship accelerator registration countdown 3 days, entrepreneurs pass through the guide in advance collection!
Software testing Q & A
STC8H8K系列匯編和C51實戰——數碼管顯示ADC、按鍵串口回複按鍵號與ADC數值
token过期自动续费方案和实现
Reading notes of cgnf: conditional graph neural fields
Go 学习笔记整合
Contest3147 - game 38 of 2021 Freshmen's personal training match_ 1: Maximum palindromes
Flutter hybrid development: develop a simple quick start framework | developers say · dtalk
来自读者们的 I/O 观后感|有奖征集获奖名单
CNN visualization technology -- detailed explanation of cam & grad cam and concise implementation of pytorch
经典文献阅读之--SuMa++
Sumo tutorial Hello World
External interrupts cannot be accessed. Just delete the code and restore it Record this unexpected bug
Stc8h8k series assembly and C51 actual combat - serial port sending menu interface to select different functions
Contest3147 - game 38 of 2021 Freshmen's personal training match_ F: Polyhedral dice
ES6的详细注解
Frequently asked questions about jetpack compose and material you
Shenji Bailian 3.52-prim
网络相关知识(硬件工程师)