일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- dotenv
- var
- loop
- C#
- generic
- AI
- git
- scss
- docker
- condition
- TypeScript
- JavaScript
- 보안
- property
- vuetify
- npm
- bash
- C++
- leetcode
- Python
- Clone
- security
- machine learning
- webpack
- vue.js
- nginx
- VUE
- 앙상블
- type
- BOJ
Archives
- Today
- Total
ice rabbit programming
[LeetCode] Climbing Stairs 본문
https://leetcode.com/problems/climbing-stairs/
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];
}
};
'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 |