일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Python
- leetcode
- JavaScript
- var
- scss
- Clone
- vue.js
- nginx
- BOJ
- generic
- C#
- AI
- security
- 보안
- property
- bash
- type
- docker
- dotenv
- vuetify
- npm
- webpack
- machine learning
- TypeScript
- condition
- git
- VUE
- C++
- 앙상블
- loop
Archives
- Today
- Total
ice rabbit programming
[LeetCode] Climbing Stairs 본문
728x90
https://leetcode.com/problems/climbing-stairs/
Climbing Stairs - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
1스텝 혹은 2스텝씩 이동하여 계단을 오르는 문제이다. 전형적인 DP 문제이다. 해당 칸까지 가는 수는 이전 칸에서 해당 칸에 오는 수만큼이기 때문이다.
Kn = Kn-1 + Kn-2의 간단한 점화식을 찾아서 구현하였다.
class Solution {
public:
int climbStairs(int n) {
vector<int> DP(n);
DP[0]=1;
if(n==1)
return DP[0];
DP[1]=2;
for(int i=2;i<n;i++) {
DP[i]=DP[i-1]+DP[i-2];
}
return DP[n-1];
}
};
728x90
'PS > LeetCode' 카테고리의 다른 글
[LeetCode] Linked List Cycle (0) | 2020.04.16 |
---|---|
[LeetCode] Remove Duplicates From Sorted List (0) | 2020.04.15 |
[LeetCode] Maximum Subarray (0) | 2020.04.15 |
[LeetCode] Valid Parenthese (0) | 2020.04.15 |
[LeetCode] Longest Common Prefix (0) | 2020.04.15 |