강의

멘토링

커뮤니티

Inflearn Community Q&A

scs0209's profile image
scs0209

asked

Introduction to Javascript Algorithm Problem Solving (Coding Test Preparation)

14. Finding combinations (important)

for문에 있는 DFS

Resolved

Written on

·

488

1

function solution(n, m) {
  let answer = [];
  let tmp = Array.from({ len
  function DFS(L, s) {
    if (L === m) {
      answer.push(tmp.slice(
    } else {
      for (let i = s; i <= n
        tmp[L] = i;
        console.log(tmp);
        DFS(L + 1, s + tmp[L]);
      }
    }
  }
  DFS(0, 1);
  return answer;
}
console.log(solution(4, 2));

강사님 저는 강의 보기전에 i + 1이 아닌 s + tmp[L]로 하니까 정답이 나오더라구요, 이렇게 해도 문제가 없 는 코드인가요?

javascript코딩-테스트

Answer 1

1

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

조합의 경우가 나오지 않는 코드 같습니다. 다음을 호출해보세요.

console.log(solution(4, 3));
scs0209님의 프로필 이미지
scs0209
Questioner

감사합니다!

scs0209's profile image
scs0209

asked

Ask a question