- 121. Best Time to Buy and Sell S
- 【2019-07-30】leetcode(121-130)
- 121 Best Time to Buy and Sell St
- LC121 Best Time to Buy and Sell
- 8.11 greedy stock, mostWater
- 714. Best Time to Buy and Sell S
- leetcode:121. Best Time to Buy a
- leetcode 122. Best Time to Buy a
- Best Time to Buy and Sell Stock
- [LeetCode] 问题系列 - 买卖股票的问题
本题链接:Best Time to Buy and Sell Stock
本题标签:Array,Dynamic Programming
本题难度:
英文题目 中文题目方案1:
class Solution {
public:
int maxProfit(vector<int>& prices) {
if(prices.size() < 2)
return 0;
int min_price = INT_MAX;
int max_profit = 0;
for(int i = 0; i < prices.size(); ++i)
{
min_price = min(min_price, prices[i]);
max_profit = max(max_profit, prices[i] - min_price);
}
return max_profit;
}
};
时间复杂度:
空间复杂度:
网友评论