P16242 [GeeksforGeeks] Permutations of a given string 1587115620
普及-
题目描述

Given a string S. The task is to find all permutations of a given string.
Example 1:
Input:
S = ABC
Output: ABC ACB BAC BCA CAB CBA
Example 2:
Input:
S = ABSG
Output: ABGS ABSG AGBS AGSB ASBG ASGB
BAGS BASG BGAS BGSA BSAG BSGA GABS
GASB GBAS GBSA GSAB GSBA SABG SAGB
SBAG SBGA SGAB SGBA

Your Task:
This is a function problem. You only need to complete the function permutation that takes S as parameter and returns the list of permutations in lexicographically increasing order. The newline is automatically added by driver code.
Constraints:
1 ≤ size of string ≤ 5
Expected Time Complexity: O(N * N!), N = length of string.
Expected Auxiliary Space: O(1)

输入格式

见题面

输出格式

见题面

样例输入
S = AAA
样例输出
AAA AAA AAA AAA AAA AAA