From bb048062c49503ac149e6abc0d6b6c4fb0386610 Mon Sep 17 00:00:00 2001 From: SquidSpirit Date: Mon, 10 Mar 2025 23:49:07 +0800 Subject: [PATCH] feat: 46_permutations --- 46_permutations/main.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 46_permutations/main.cpp diff --git a/46_permutations/main.cpp b/46_permutations/main.cpp new file mode 100644 index 0000000..ec43d8f --- /dev/null +++ b/46_permutations/main.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; + +class Solution { + public: + vector> permute(vector& nums) { + vector> result; + + sort(nums.begin(), nums.end()); + result.emplace_back(nums); + + while (next_permutation(nums.begin(), nums.end())) { + result.emplace_back(nums); + } + return result; + } +};