diff options
Diffstat (limited to 'next_permutation.cpp')
-rw-r--r-- | next_permutation.cpp | 37 |
1 files changed, 0 insertions, 37 deletions
diff --git a/next_permutation.cpp b/next_permutation.cpp deleted file mode 100644 index 95e70f4..0000000 --- a/next_permutation.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include <bits/stdc++.h> -#include <vector> -using namespace std; - -class Solution { -public: - void nextPermutation(vector<int> &nums) { - int i = nums.size() - 2; - while (i >= 0 && nums[i + 1] <= nums[i]) - i--; - if (i >= 0) { - int j = nums.size() - 1; - while (nums[j] <= nums[i]) - j--; - swap(nums, i, j); - } - reverse(nums, i + 1); - } - -private: - void reverse(vector<int> &nums, int start) { - int i = start, j = nums.size() - 1; - while (i < j) { - swap(nums, i, j); - i++; - j--; - } - } - - void swap(vector<int> &nums, int i, int j) { - int temp = nums[i]; - nums[i] = nums[j]; - nums[j] = temp; - } -}; - -int main() {} |