题解 | #没有重复项数字的全排列#
没有重复项数字的全排列
https://www.nowcoder.com/practice/4bcf3081067a4d028f95acee3ddcd2b1
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param num int整型vector * @return int整型vector<vector<>> */ vector<vector<int> > permute(vector<int>& num) { vector<vector<int>> res; vector<vector<int>> cur; if (num.empty()) return res; if (num.size() == 1) res.push_back(num); else { int elem = num.back(); num.pop_back(); cur = permute(num); for (int i = 0; i < cur.size(); i++) { for (int j = 0; j <= cur.at(i).size(); j++) { vector<int> row = cur.at(i); row.insert(row.begin() + j, elem); res.push_back(row); } } } return res; } };
为啥通过了捏?没按顺序来啊