当前位置:网站首页>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;
}
};
边栏推荐
- The (3n+1) conjecture that C language kills people without paying for their lives
- Chiffrement des cookies 8
- 魔百盒CM201-2-CH-Hi3798MV300-300H-EMMC和NAND_红外蓝牙语音_通刷固件包
- [machine learning Q & A] accuracy, accuracy, recall, ROC and AUC
- 搞透AQS原理(流程图及同步队列图解)
- Derivation of univariate polynomial in C language
- MySQL monitoring 1
- C language I want to pass
- Kubernetes core object overview details
- 画画水族馆的应用特色及功能
猜你喜欢
[recommendation system] concise principle and code implementation of user based collaborative filtering
【PyTorch实战】生成对抗网络GAN:生成动漫人物头像
Mobaihe cm201-2-ch-hi3798mv300-300h-emmc and NAND_ Infrared Bluetooth voice_ Brush firmware package
C语言 我要通过
DTW learning (dynamic time warping) -- Thought and code implementation
How to seamlessly transition from traditional microservice framework to service grid ASM
Write this number in C
C language number prime
C语言 说反话
cookie加密8
随机推荐
ctfshow 大赛原题 680-695
Varnish 基础概览3
C语言 害死人不偿命的(3n+1)猜想
[mrctf2020]ezpop-1 | PHP serialization
Cookie encryption 8
Cookie加密15 登录加密
Scala基础【入门及安装】
If you want to install a set of monitoring, what is the process? How much is it?
Embedded test template
Can mango hypermedia, which "braves the wind and waves", go ashore?
Conversion between opencv and image (valid for pro test)
ES6 synchronous asynchronous execution and block level scope
Internal class usage scenarios, syntax and principle explanations
搞透AQS原理(流程图及同步队列图解)
C语言 数组元素循环右移问题
Circular right shift of array elements in C language
MySQL monitoring 1
第八届“互联网+”大赛 | 云原生赛道邀你来挑战
Cookie encryption 13
Design and implementation of spark offline development framework