We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Difficulty: 中等
Related Topics: 数组, 回溯
给定一个不含重复数字的数组 nums ,返回其 所有可能的全排列 。你可以 按任意顺序 返回答案。
nums
示例 1:
输入:nums = [1,2,3] 输出:[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
示例 2:
输入:nums = [0,1] 输出:[[0,1],[1,0]]
示例 3:
输入:nums = [1] 输出:[[1]]
提示:
1 <= nums.length <= 6
-10 <= nums[i] <= 10
Language: JavaScript
/** * @param {number[]} nums * @return {number[][]} * 广度优先遍历 * 深度优先遍历 */ var permute = function(nums) { const ans = [] const dfs = (item = []) => { if (item.length === nums.length) return ans.push([...item]) nums.forEach(num => { if (!item.includes(num)) { dfs([...item, num]) } }) } dfs() return ans }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
46. 全排列
Description
Difficulty: 中等
Related Topics: 数组, 回溯
给定一个不含重复数字的数组
nums
,返回其 所有可能的全排列 。你可以 按任意顺序 返回答案。示例 1:
示例 2:
示例 3:
提示:
1 <= nums.length <= 6
-10 <= nums[i] <= 10
nums
中的所有整数 互不相同Solution
Language: JavaScript
The text was updated successfully, but these errors were encountered: