刷 leetcode ,46 题 Permutations 一个作弊的方法是直接使用 C++20 新标准中的 next_permutation API:
do{
res.push_back(nums);
} while (next_permutation(nums.begin(), nums.end()));
但需要注意,next_permutation(start, end) API 需要被寻找的数组是有序数组,也即在进入循环之前需要完成一次 sort .
刷 leetcode ,46 题 Permutations 一个作弊的方法是直接使用 C++20 新标准中的 next_permutation API:
do{
res.push_back(nums);
} while (next_permutation(nums.begin(), nums.end()));
但需要注意,next_permutation(start, end) API 需要被寻找的数组是有序数组,也即在进入循环之前需要完成一次 sort .