当前位置:网站首页>Leetcode 46 Full arrangement (February 15, 2022)
Leetcode 46 Full arrangement (February 15, 2022)
2022-06-30 01:44:00 【ChaoYue_ miku】
Give an array without duplicate numbers nums , Back to its All possible permutations . You can In any order Return to the answer .
Example 1:
Input :nums = [1,2,3]
Output :[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
Example 2:
Input :nums = [0,1]
Output :[[0,1],[1,0]]
Example 3:
Input :nums = [1]
Output :[[1]]
Tips :
1 <= nums.length <= 6
-10 <= nums[i] <= 10
nums All integers in Different from each other
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/permutations
Method 1 :DFS+ to flash back
C++ Submission :
class Solution {
public:
void backtrack(vector<vector<int>>& res, vector<int>& output, int first, int len){
if(first == len){
res.emplace_back(output);
return;
}
for(int i = first; i < len; ++i){
swap(output[first], output[i]);
backtrack(res, output, first + 1, len);
swap(output[first], output[i]);
}
}
vector<vector<int>> permute(vector<int>& nums) {
vector<vector<int>> res;
backtrack(res, nums, 0, int(nums.size()));
return res;
}
};
边栏推荐
- What should I do when I feel confused after graduation from university?
- The first technology podcast month will be launched soon
- GeoTools:WKT、GeoJson、Feature、FeatureCollection相互转换常用工具
- Varnish 基础概览8
- 假离婚变成真离婚,财产怎么办
- [graph neural network] overview of graph classification learning [2]: graph classification based on graph neural network
- [machine learning Q & A] data sampling and model verification methods, hyperparametric optimization, over fitting and under fitting problems
- Varnish 基础概览2
- Conjecture of prime pairs in C language
- Is the processor the main factor in buying a mobile phone?
猜你喜欢
![[535. encryption and decryption of tinyurl]](/img/b7/7748febe30852ca428fe86b045e9ca.png)
[535. encryption and decryption of tinyurl]
![[MRCTF2020]Ezpop-1|php序列化](/img/65/9b7a3ae3552d8784b0c77a1130d762.png)
[MRCTF2020]Ezpop-1|php序列化

Ansible ad-hoc 临时命令
![[pytorch actual combat] generate confrontation network Gan: generate cartoon character avatars](/img/8f/c0cc1c8d19060a60d92c0d72f8b93d.png)
[pytorch actual combat] generate confrontation network Gan: generate cartoon character avatars

js返回内容被unicode编码

Derivation of univariate polynomial in C language

DTW学习(dynamic time warping)——思想、代码实现

当大学毕业感到迷茫怎么办?

Scala基础【入门及安装】

JS content confusion, return content encryption
随机推荐
JS anti shake and throttling
Understand AQS principle (flow chart and synchronous queue diagram)
[machine learning Q & A] data sampling and model verification methods, hyperparametric optimization, over fitting and under fitting problems
Varnish 基础概览8
A summary of the quantification of deep network model
What is idempotency? Detailed explanation of four interface idempotence schemes!
【机器学习Q&A】余弦相似度、余弦距离、欧式距离以及机器学习中距离的含义
C语言 数组元素循环右移问题
GeoTools WKT坐标系转换
Understanding of int argc, char * * argv in C language main function
MySQL monitoring 2
[graph neural network] overview of graph classification learning [2]: graph classification based on graph neural network
Cookie加密13
工具与生活服务
Geotools: common tools for mutual conversion of wkt, geojason, feature and featurecollection
Geotools wkt coordinate system conversion
win10子系统 WSL如果root和其他用户的密码都忘记的修复方法
Varnish foundation overview 3
JS returned content is encoded by Unicode
Three questions from the boss