LeetCode (Permutations)
来源:互联网 发布:大芒果专用数据修改 编辑:程序博客网 时间:2024/05/20 00:16
Problem:
Given a collection of distinct numbers, return all possible permutations.
For example,[1,2,3]
have the following permutations:
[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]
Solution:class Solution {public: vector<vector<int>> permute(vector<int>& nums) { vector<vector<int>> ans; if (nums.empty() || nums.size() == 1){ return {nums}; } vector<int> num = nums; num.erase(num.begin()); vector<vector<int>> b = permute(num); for (int j = 0; j < b.size(); j++) for (int l = 0; l < nums.size(); l++){ vector<int> p = b[j]; p.insert(p.begin() + l, nums[0]); ans.push_back(p); } return ans; }};
0 0
- 【LeetCode】Permutations && Permutations II
- leetcode: Permutations/Permutations II
- leetcode Permutations & Permutations II
- [Leetcode]Permutations && Permutations II
- LeetCode: Permutations
- LeetCode: Permutations
- [Leetcode] Permutations
- [LeetCode] Permutations
- Leetcode: Permutations
- [Leetcode] Permutations
- [Leetcode] Permutations
- [LeetCode]Permutations
- LeetCode-Permutations
- [leetcode] permutations
- LeetCode - Permutations
- Leetcode: Permutations
- 【leetcode】Permutations
- 【LeetCode】Permutations
- Tensorflow学习:单层神经网络的建立
- cipher加密解密
- HDOJ 2011 多项式求和
- hdu5391Zball in Tina Town(素数鉴别的大猜想)
- 本blog停更,以后将使用个人blog站点:www.haibusuanyun.com
- LeetCode (Permutations)
- 1048: 【亲和数】
- HttpClient4.X 升级 入门 + http连接池使用
- C++在一定范围内生成不重复随机数序列
- 《深入理解java虚拟机》笔记之一——java内存区域与内存溢出异常
- 指针和引用的区别
- 为响应式布局而生的viewport
- GIT命令_全
- 图文笔记,带你走进《未来简史》(21-25)