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
给定一个 没有重复 数字的序列,返回其所有可能的全排列。
Input: [1,2,3] Output: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ]
The text was updated successfully, but these errors were encountered:
/** * @param {number[]} nums * @return {number[][]} */ var permute = function(nums) { const result = []; const cache = new Set(); backtracking(); return result; function backtracking() { if (cache.size === nums.length) { result.push([...cache]); return; } for (let i = 0; i < nums.length; i++) { if (!cache.has(nums[i])) { cache.add(nums[i]); backtracking(); cache.delete(nums[i]); } } } };
Sorry, something went wrong.
No branches or pull requests
46. Permutations
给定一个 没有重复 数字的序列,返回其所有可能的全排列。
Example
The text was updated successfully, but these errors were encountered: