leetcode 刷题之路 12 Permutations
来源:互联网 发布:ip域名是什么意思 编辑:程序博客网 时间:2024/06/07 15:16
Given a collection of 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]
, and [3,2,1]
.
全排列问题,详细分析参考这篇文章,这里不再赘述,直接贴出代码。
class Solution {public:vector<vector<int> > permute(vector<int> &num){vector<vector<int>> result;helper(num, result, 0, num.size());return result;}static void helper(vector<int> &num,vector<vector<int>> &result, int current, int len){if (current == len){result.push_back(num);return;}for (int i = current; i < len; i++){swap(num[current], num[i]);helper(num, result, current + 1, len);swap(num[current], num[i]);}}static void swap(int &a, int &b){int temp = a;a = b;b = temp;}};
0 0
- leetcode 刷题之路 12 Permutations
- leetcode 刷题之路 77 Permutations II
- leetcode之路046 Permutations
- LeetCode算法题之Permutations
- [leetcode刷题系列]Permutations
- LeetCode进阶之路(Permutations)
- LeetCode进阶之路(Permutations II)
- LeetCode第46题之 Permutations
- LeetCode第47.题之Permutations II
- leetcode之Permutations
- leetcode之Permutations II
- 【Leetcode】之 Permutations
- 【Leetcode】之Permutations II
- LeetCode 之 Permutations
- 【LeetCode】马三来刷题之Permutations
- leetcode之Permutations问题
- [leetcode刷题系列]Permutations II
- LeetCode刷题笔录Permutations II
- 数组指针和指针数组
- hdu4292 Food 网络最大流 拆点
- POJ_3090_Visible Lattice Point_欧拉函数
- 通过Gradle自动生成通过Git提交的version
- uva 270 Lining Up
- leetcode 刷题之路 12 Permutations
- Java--java中多态知识介绍
- Nested Type
- java创建对象的四种方法
- 和你好地方还是大富豪个符合时代
- uva 122 - Trees on the level(一棵看着书都写不利索的树……)
- 简单去标签
- C++仿函数(functor)
- github开源项目介绍-使用pygrok轻松解析字符串(log, event..)