Shawn's Blog

  • Home
  • Tags
  • Categories
  • Archives
  • Search
  • Table of Contents
  • Overview

Shawn

若有恒,何必三更眠五更起;最无益,莫过一日曝十日寒。
392 posts
13 categories
114 tags

LeetCode 746. Min Cost Climbing Stairs

Posted on 2020-12-21 Edited on 2024-11-24 In LeetCode
1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
public:
int minCostClimbingStairs(vector<int>& cost) {
int n = cost.size(), first = cost[0], second = cost[1], third, i = 2;
while (i < n) {
third = min(first, second) + cost[i++];
first = second;
second = third;
}
return min(first, second);
}
};
# Dynamic Programming# Array
LeetCode 860. Lemonade Change
LeetCode 103. Binary Tree Zigzag Level Order Traversal
© 2024 Shawn
Powered by Hexo & NexT.Mist
0%