当前位置:网站首页>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;
}
};
边栏推荐
猜你喜欢
随机推荐
Pytorch 修改hook源码 获取Per-Layer输出参数(带layer name)
A summary of the quantification of deep network model
Understand AQS principle (flow chart and synchronous queue diagram)
Mysql 监控3
[recommendation system] concise principle and code implementation of user based collaborative filtering
Cookie encryption 8
【机器学习Q&A】余弦相似度、余弦距离、欧式距离以及机器学习中距离的含义
假离婚变成真离婚,财产怎么办
Application features and functions of painting Aquarium
MySQL monitoring 3
C语言 我要通过
js内容混淆,返回内容加密
Geotools wkt coordinate system conversion
What should be paid attention to in the design and production of the Urban Planning Museum
Varnish foundation overview 8
JS anti shake and throttling
Embedded test template
Pytoch modifies the hook source code to obtain per layer output parameters (with layer name)
【PyTorch实战】生成对抗网络GAN:生成动漫人物头像
Conversion between opencv and image (valid for pro test)








