알고리즘

[LeetCode] Permutations

룰스 2019. 10. 28. 17:38

문제

Given a collection of distinct integers, return all possible permutations.

Example:

Input: [1,2,3] Output: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ]

 

Approach

https://noname122.tistory.com/13

 

[LeetCode] Next Permutation

문제 Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest poss..

noname122.tistory.com

이 문제의 확장판으로 여기 있는 알고리즘과 똑같이 하되, 한바퀴 다 돌면 반복문을 빠져나오게 만들면 된다.

나중에 안 사실이지만 *next_permutation()이라는 함수가 있음.

이걸로 하면 내부 구현할 필요도 없다.

 

Code

https://github.com/chi3236/algorithm/blob/master/LeetCode_Permutations.cpp

 

chi3236/algorithm

Contribute to chi3236/algorithm development by creating an account on GitHub.

github.com

https://github.com/chi3236/algorithm/blob/master/LeetCode_Permutation_NextPermutation.cpp

불러오는 중입니다...