Given a collection of distinct numbers, return all possible permutations.
For example,
[1,2,3] have the following permutations:
[
[1,2,3],
[1,3,2],
[2,1,3],
[2,3,1],
[3,1,2],
[3,2,1]
]
[LeetCode]–31. Next Permutation
做过这个题之后,肯定启发很多,所以我很快就写出来了。
public List<List<Integer>> permute(int[] nums) {
List<List<Integer>> res = new ArrayList<List<Integer>>();
if (nums.length ==

这篇博客探讨了LeetCode中的46题,即如何找到给定一组唯一数字的所有可能排列。作者分享了自己的解决方案,并提到先前解决31题对其启发很大,使得能高效地找出所有序列。还提供了一个不同的解答供读者参考,尽管该解答效率稍低,但代码更为简洁。
订阅专栏 解锁全文
698

被折叠的 条评论
为什么被折叠?



