diff --git a/C++/nextpermutation.cpp b/C++/nextpermutation.cpp new file mode 100644 index 0000000..29818e6 --- /dev/null +++ b/C++/nextpermutation.cpp @@ -0,0 +1,33 @@ +class Solution { +public: + void nextPermutation(vector &num) { + // Start typing your C/C++ solution below + // DO NOT write int main() function + int sz = num.size(); + int k=-1; + int l; + //step1 + for (int i=0;inum[k]){ + l=i; + } + } + //step3 + int tmp = num[l]; + num[l]=num[k]; + num[k]=tmp; + //step4 + reverse(num.begin()+k+1,num.end()); + } +};