class Solution {
public:
vector<vector<int> > permute(vector<int> &num) {
vector<vector<int>> result;
if (num.size() == 0)
return result;
sort(num.begin(), num.end());
permute(num, 0, result);
return result;
}
private:
void permute(vector<int> &num, size_t start, vector<vector<int>> &result){
if (start == num.size()1){
result.push_back(num);
}
else{
for (size_t i = start; i < num.size(); i++){
swap(num[start], num[i]);
permute(num, start + 1, result);
swap(num[start], num[i]);
}
}
}
};
My AC Solution in C++, I think this is not dfs, is it?


Thanks for your post. However it would be better to share solution with correct code format and elaborated thoughts. Please read the Discuss FAQ for more info. Take a look at good sharing example