leetcode_permutaion
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int a[3] = { 1,3,2}; vector<int>num(a, a + 3); auto rfirst = num.rbegin(); auto rend = num.rend(); auto p = next(rfirst); while (p != rend && *p > *(prev(p))) ++p; if (p == rend) reverse(num.begin(), num.end()); else { for (auto i = rfirst; i!=rend; ++i) { if (*i > *p)swap(*i, *p); reverse(rfirst, i); } } for (auto i : num) { cout << i << " "; } system("pause"); return 0; }