← 返回 apple 的题目列表Generate All Permutations
类型:online_judge
Problem
Given an array nums of distinct integers, return all permutations of nums.
Input
Line 1: integer n (length of the array)
Line 2: n integers representing nums
Output
Print all permutations, one per line, elements separated by spaces.
Any order is acceptable.
Constraints
1 <= n <= 9
All elements in nums are distinct
Example
Input:
3
1 2 3
Example output:
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
Note
Implement a program/function to generate all permutations.
Example
Input
1
5
Output
5