题解 | #有重复项数字的全排列#
有重复项数字的全排列
https://www.nowcoder.com/practice/a43a2b986ef34843ac4fdd9159b69863
#include <vector> #include <algorithm> using namespace std; class Solution { public: vector<vector<int>> permuteUnique(vector<int> &num) { vector<vector<int>> result; sort(num.begin(), num.end()); // 先排序,以便处理重复元素 do { result.push_back(num); // 将当前排列添加到结果中 } while (next_permutation(num.begin(), num.end())); return result; } };