dkswnkk 2021. 11. 10. 23:43

문제

 

Permutations - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

μ½”λ“œ

class Solution {
public:
    vector<vector<int>> permute(vector<int>& nums) {

        vector<vector<int>>ans;
        sort(nums.begin(),nums.end());
        do{
            ans.push_back(nums);
        }while(next_permutation(nums.begin(),nums.end()));
        return ans;
    }

};

 

풀이

λ‹¨μˆœν•˜κ²Œ μˆœμ—΄μ„ κ΅¬ν•˜λŠ” λ¬Έμ œμž…λ‹ˆλ‹€. algorithm 헀더 νŒŒμΌμ— λ‚΄μž₯λ˜μ–΄μžˆλŠ” net_permutation ν•¨μˆ˜λ₯Ό μ‚¬μš©ν•˜λ©΄ μ‰½κ²Œ ν•΄κ²°ν•  수 μžˆμŠ΅λ‹ˆλ‹€.