Skip to content

Commit 216f492

Browse files
authored
Merge pull request #81 from InflixOP/patch1
Patch1
2 parents 2a15562 + bbdf3ad commit 216f492

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

#1137. N-th Tribonacci Number.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
int tribonacci(int n) {
4+
vector<int> dp(n+1,0);
5+
if(n>=1)
6+
dp[1]=1;
7+
if(n>=2)
8+
dp[2]=1;
9+
for(int i=3;i<=n;i++)
10+
dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
11+
return dp[n];
12+
}
13+
};

#746. Min Cost Climbing Stairs.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
int minCostClimbingStairs(vector<int>& cost) {
4+
int n=cost.size();
5+
vector<int> dp(n,0);
6+
dp[0]=cost[0];
7+
dp[1]=cost[1];
8+
for(int i=2;i<n;i++){
9+
int l=dp[i-1]+cost[i];
10+
int r=dp[i-2]+cost[i];
11+
dp[i]=min(l,r);
12+
}
13+
return min(dp[n-1],dp[n-2]);
14+
}
15+
};

0 commit comments

Comments
 (0)