classSolution { public: voidnextPermutation(vector<int>& nums){ int i = 0; int n = nums.size(); for (i = n-2; i >= 0; i-- ) { if (nums[i+1] > nums[i]) { break; } } if (i >= 0) { int j; for (j = n-1; j >= i+1; j--) { if (nums[j] > nums[i]) { swap(nums[j], nums[i]); break; } } int l = i+1, r = n-1; while (l < r) { swap(nums[l], nums[r]); l++; r--; } return; } else { int l = 0, r = n-1; while (l < r) { swap(nums[l], nums[r]); l++; r--; } return; } } };