λ¬Έμ
νμ΄ κ³Όμ
μ£Όμ΄μ§ λ°°μ΄λ‘ μμ΄μ λ§λλ λ¬Έμ μ
λλ€. λ°±νΈλνΉ
μ ν΅ν΄ λ°°μ΄μ μμλ€μ νλμ© μννλ©° μμ΄μ λ§λ€μ΄μ£Όλ©΄ λ©λλ€.
μ΄λ λ°°μ΄ μ°μ°μΌλ‘ push or pop
μ μ¬μ©νμ§ μκ³ javascript
μ spread
μ°μ°μλ‘
μλ‘μ΄ λ°°μ΄μ λ§λ€μ΄ λ겨주λ λ°©μμ μ¬μ©νμ΅λλ€.
μ½λ
/**
* @param {number[]} nums
* @return {number[][]}
*/
var permute = function (nums) {
const ans = [];
function permutation(selected) {
if (selected.length === nums.length) {
ans.push(selected);
return;
}
for (let i = 0; i < nums.length; i++) {
if (!selected.includes(nums[i])) {
permutation([...selected, nums[i]]);
}
}
}
permutation([]);
return ans;
};
λ°μν
'π algorithm > leetcode' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
LeetCode 347 - Top K Frequent Elements (Medium) (0) | 2021.03.03 |
---|---|
LeetCode 322 - Coin Change (Medium) (0) | 2021.03.03 |
LeetCode 21 - Merge Two Sorted Lists (Easy) (0) | 2021.03.02 |
LeetCode 240 - Search a 2D Matrix II (Medium) (0) | 2021.03.02 |
LeetCode 155 - Min Stack (Easy) (0) | 2021.03.02 |
π¬ λκΈ