请教一个同步的问题# PDA - 掌中宝
f*m
1 楼
1. Permutation Sequence
The set [1,2,3,…,n] contains a total of n! unique permutations.
By listing and labeling all of the permutations in order,
We get the following sequence (ie, for n = 3):
"123"
"132"
"213"
"231"
"312"
"321"
Given n and k, return the kth permutation sequence.
Note: Given n will be between 1 and 9 inclusive.
我目前的做法是计算出所有的permuation sequence,然后输出第k个。大家有根好的方
法吗?
2. Permutations II
Given a collection of numbers that might contain duplicates, return all
possible unique permutations.
For example,
[1,1,2] have the following unique permutations:
[1,1,2], [1,2,1], and [2,1,1].
我用set 存permutation的结果,包括中间过程产生的permutation。有更好的方法吗?
谢谢
The set [1,2,3,…,n] contains a total of n! unique permutations.
By listing and labeling all of the permutations in order,
We get the following sequence (ie, for n = 3):
"123"
"132"
"213"
"231"
"312"
"321"
Given n and k, return the kth permutation sequence.
Note: Given n will be between 1 and 9 inclusive.
我目前的做法是计算出所有的permuation sequence,然后输出第k个。大家有根好的方
法吗?
2. Permutations II
Given a collection of numbers that might contain duplicates, return all
possible unique permutations.
For example,
[1,1,2] have the following unique permutations:
[1,1,2], [1,2,1], and [2,1,1].
我用set 存permutation的结果,包括中间过程产生的permutation。有更好的方法吗?
谢谢