← 返回 oracle 的题目列表Generate all permutations of a list
类型:online_judge
Problem
Given an array nums of distinct integers, return all possible permutations.
You may output the answer in any order.
Input
Line 1: integer n (length of the array)
Line 2: n integers for nums
Output
Print all permutations, one per line, numbers separated by spaces.
Constraints
1 <= n <= 9
All elements in nums are distinct
Examples
Input:
3
1 2 3
Output (any order):
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
Example
Input
3
1 2 3
Output
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1