상위 150개 인터뷰쉬움

순열

'순열' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

고유한 정수의 배열이 주어지면 가능한 모든 순열을 반환합니다. 어떤 순서로든 답변을 반환할 수 있습니다.

permute(nums: list) -> list 함수를 구현하세요.

제약
  • 1 <= nums.length <= 6
  • -10 <= nums[i] <= 10
  • All the integers of nums are unique

Example 1
Input
[1,2,3]
Output
[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
Explanation

All 3! = 6 permutations of [1,2,3] are generated.

Example 2
Input
[0,1]
Output
[[0,1],[1,0]]
Explanation

All 2! = 2 permutations of [0,1] are generated.

Example 3
Input
[1]
Output
[[1]]
Explanation

Only one permutation exists for a single element.

Need a Hint?
세트 또는 힙과 같은 역추적 관련 데이터 구조를 사용하는 것이 좋습니다.
Edge Cases to Watch
  • 빈 입력 구조
  • 단일 요소 입력
  • 큰 수치 범위

해결할 준비가 되셨나요?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

편집기에서 열기
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

권장 Python 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.