반응형
https://leetcode.com/problems/climbing-stairs/description
class Solution {
public:
int climbStairs(int n) {
if (n <= 1) return 1;
int dp[3] = {1, 1, 0};
for(int i=2; i<=n; i++) {
dp[2] = dp[0] + dp[1];
dp[0] = dp[1];
dp[1] = dp[2];
}
return dp[2];
}
};
반응형
'Algorithm' 카테고리의 다른 글
LeetCode 645. Set Mismatch (1) | 2024.01.22 |
---|---|
LeetCode 931. Minimum Falling Path Sum (0) | 2024.01.20 |
LeetCode 380. Insert Delete GetRandom O(1) (0) | 2024.01.18 |
LeetCode 2225. Find Players With Zero or One Losses (0) | 2024.01.15 |
LeetCode 1347. Minimum Number of Steps to Make Two Strings Anagram (0) | 2024.01.13 |