- LeetCode #121 #122 #123 #188 #30
- #121. Best Time to Buy and Sell
- leetcode:121. Best Time to Buy a
- [LeetCode] 121. Best Time to Buy
- Leetcode121 - 123 (dp problems)
- [数组]121. Best Time to Buy and Se
- 121. Best Time to Buy and Sell S
- Leetcode121-Best Time to Buy and
- 每天(?)一道LeetCode(14) Best Time to
- Leetcode 股票合集 【121、122、714、309】
Best Time to Buy and Sell Stock
这是一道easy题,考察Dynamic programming。因为刚打开leetcode 309, Best Time to Buy and Sell Stock with Cooldown, 所以就把leetcode121这道题拿出来复习了一下
class Solution {
public:
int maxProfit(vector<int>& prices) {
int max_profit = 0;
int min_price = INT_MAX;
for (auto p: prices) {
min_price = min(min_price, p);
max_profit = max(max_profit, p - min_price);
}
return max_profit;
}
};
网友评论