순열1 [LeetCode] 46. Permutations 순열 (Javascript) https://leetcode.com/problems/permutations/ var permute = function(nums) { return nums.reduce( function(list, element) { var newlist = []; list.forEach(function(seq) { for (var i = seq.length; i >= 0; i--) { var newseq = [].concat(seq); newseq.splice(i, 0, element); newlist.push(newseq); } }); return newlist; }, [[]] ); }; 순열 이해하기가 왜이렇게 어려운지.. 요약하면, 반복을 돌며 값을 고정해나가는 방식이다. [1, 2]이 있다고 하면, 배열 길이만큼.. 2020. 7. 22. 이전 1 다음