vector<vector<int> > res;
sort(num.begin(), num.end());
res.push_back(num);
if(num.size() < 2){
return res;
}
while(true){
int i = num.size() - 1;
while(true){
int ii = i;
--i;
if(num[i] < num[ii]){
int j = num.size();
while(num[i] >= num[--j]);
swap(num[i], num[j]);
reverse(num.begin() + ii, num.end());
res.push_back(num);
break;
}
if(i == 0){
return res;
}
}
}
leetcode: Permutations I II
最新推荐文章于 2024-11-06 23:21:54 发布