LeetCode Permutation
2012-11-24 00:08
316 查看
Permutations
Given a collection of numbers, return all possible permutations.
For example,
the following permutations:
and
Solution:
class Solution {
public:
vector<vector<int> > permute(vector<int> &num) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
sort(num.begin(),num.end());
vector<vector<int> > result;
do{
result.push_back(num);
}while(next_permutation(num.begin(),num.end()));
return result;
}
};
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].
Solution:
class Solution {
public:
vector<vector<int> > permute(vector<int> &num) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
sort(num.begin(),num.end());
vector<vector<int> > result;
do{
result.push_back(num);
}while(next_permutation(num.begin(),num.end()));
return result;
}
};
相关文章推荐
- LeetCode-Palindrome Permutation II
- Leetcode 60: Permutation Sequence
- [leetcode]Permutation Sequence
- Leetcode刷题系列(一)Subsets 与 Permutation
- [leetcode 60] Permutation Sequence
- LeetCode Permutation Sequence(求排列中的第k个排列是什么)
- LeetCode解题报告—— Jump Game & Merge Intervals & Permutation Sequence
- LeetCode 60 - Permutation Sequence
- leetcode:Permutation Sequence (顺序排列第k个序列) 【面试算法题】
- LeetCode OJ Permutation Sequence
- [LeetCode 题解]: Permutation Sequcence
- leetcode — next-permutation
- leetCode_Permutation Sequence
- leetcode permutation
- Next Permutation -- LeetCode(下一个字典序)
- leetcode:回溯——permutation-sequence,
- [leetcode]Next Permutation @ Python
- 【leetcode】 Permutations 一个简单next_permutation的实现
- leetcode -- permutation 总结
- LeetCode Next Permutation