返回题库

全排列

Permutations

专题
Algorithmic Programming / 算法编程
难度
L3
来源
Citadel

题目详情

问题:全排列

考察:数组、回溯

来源:DSA Prep / Citadel

链接:https://leetcode.com/problems/permutations

英文原题

Problem: Permutations

Patterns: Array, Backtracking

Recency: 2yr

Link: https://leetcode.com/problems/permutations

Source: https://www.dsaprep.dev/blog/citadel-coding-interview-questions/

解析

思路:回溯构造排列,用 used 数组标记哪些数字已被选择。路径长度达到 n 时记录一个排列。

复杂度:时间 O(n! * n),空间 O(n) 不计输出。


英文解析

Approach: Use backtracking with a `used` array. At each depth choose one unused number, append it, recurse, and then undo the choice.

Complexity: Time O(nn!)O(n\cdot n!), space O(n)O(n) excluding output.