Skip to content

Conversation

@Seoin02
Copy link
Contributor

@Seoin02 Seoin02 commented Sep 20, 2024

✔ 문제 제목: 계단오르기

✔ 문제 유형: DP

✔ 문제 풀이 날짜: 2024.09.20

💡 문제 분석 요약

  • 철수는 계단 1개 또는 2개를 한 번에 오를 수 있다.

💡 알고리즘 설계

  • dp 배열을 만든다.
  • n번째 계단은 n-1번째 계단에서 1칸 올라가거나 n-2번째 계단에서 2칸 올라가면 된다.
  • n번째 계단은 n-1번째 계단에 도착하는 방법 수와 n-2번째 계단에 도착하는 방법 수를 더한 것이다.

💡코드

function solution(n) {
  if (n === 1) return 1;
  if (n === 2) return 2;

  let dp = new Array(n + 1).fill(0);
  dp[1] = 1;
  dp[2] = 2;

  for (let i = 3; i <= n; i++) {
    dp[i] = dp[i - 1] + dp[i - 2];
  }
  return dp[n]
}

💡 시간복잡도

O(n)

💡 틀린 이유와 틀린 부분 수정 or 다른 풀이

// 다른 풀이를 작성해주세요 !

💡 느낀 점 or 기억할 정보

  • 새로운 유형이군요. 태풍의 눈...?

Copy link
Contributor

@devwqc devwqc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋아요~ 🐾

아니 이거 어떻게 푸셨어요!! 저는 어떻게 접근하면 좋을지 아예 떠오르질 않더라구요...
마지막 섹션 파이팅! 👏💪👏💪👏💪👏💪👏💪👏💪👏💪👏💪👏💪👏💪👏💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants