wherehows
Home
  • 분류 전체보기 (35)
    • 알고리즘 (31)
      • 코드트리 (0)
      • 백준 (1)
      • 리트코드 (21)
      • 프로그래머스 (9)
Home
  • 분류 전체보기 (35)
    • 알고리즘 (31)
      • 코드트리 (0)
      • 백준 (1)
      • 리트코드 (21)
      • 프로그래머스 (9)
블로그 내 검색

wherehows

  • 알고리즘/리트코드

    Permutations II

    2021. 5. 12.

    by. 창고

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    var permuteUnique = function (nums) {
        let res = []; let remain = {}; let set = new Set(nums);
        for (let i = 0; i < nums.length; i++) {
            remain[nums[i]] = remain[nums[i]] + 1 || 1;
        }
     
        function permute(depth, getArray, getRemain) {
            if (depth === nums.length) {
               res.push(getArray); ❓❓ getArray.slice()로 해야함
                return;
            } else {
                for (let num of set) {
                    if (remain[num]) {
                        getArray.push(num);
                        getRemain[num]--;
     
                        permute(depth + 1, getArray, getRemain);
     
                        getArray.pop();
                        getRemain[num]++;
                    }
                }
            }
        }
     
        permute(0, [], remain);
     
        return res;
    };
     
    console.log(permuteUnique([1, 1, 2]));
    cs

    '알고리즘 > 리트코드' 카테고리의 다른 글

    53. Maximum Subarray  (0) 2021.05.23
    121. Best Time to Buy and Sell Stock  (0) 2021.05.23
    1557. Minimum Number of Vertices to Reach All Nodes  (0) 2021.05.20
    1277. Count Square Submatrices with All Ones  (0) 2021.05.20
    1641. Count Sorted Vowel Strings  (0) 2021.05.20

    댓글

    관련글

    • 121. Best Time to Buy and Sell Stock 2021.05.23
    • 1557. Minimum Number of Vertices to Reach All Nodes 2021.05.20
    • 1277. Count Square Submatrices with All Ones 2021.05.20
    • 1641. Count Sorted Vowel Strings 2021.05.20
    맨 위로
전체 글 보기
Tistory 로그인
Tistory 로그아웃
로그아웃 글쓰기 관리

Today

Total

Powered by ⓒ Kakao Corp.

Designed by Nana
블로그 이미지
창고

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.