mirror of
https://github.com/ShusenTang/LeetCode.git
synced 2024-09-02 14:20:01 +00:00
update 46
This commit is contained in:
parent
fe13c3369b
commit
811f141473
@ -2,7 +2,7 @@
|
||||
# 思路
|
||||
返回一个数组的所有排列,数组中元素没有重复。
|
||||
## 思路一、Next Permutation
|
||||
如果做了[31. Next Permutation](https://leetcode.com/problems/next-permutation/)的话那这题就没什么问题了。稍有不同的是此题的数组元素没有重复而39题中可能重复。
|
||||
如果做了[31. Next Permutation](https://leetcode.com/problems/next-permutation/)的话那这题就没什么问题了。稍有不同的是此题的数组元素没有重复而31题中可能重复。
|
||||
所以此题可以使用STL中现成的next_permutation函数:
|
||||
> bool next_permutation (first, last)返回的是bool型,如果已经是最后一个排列了则返回false并将数组变成第一个排列(即按照从小到大排好序);否则返回true并将数组变成下一个排列。
|
||||
此外还可以传入comp参数: next_permutation (first, last, comp)这样就可以自定义数组的大小规则。
|
||||
|
Loading…
Reference in New Issue
Block a user