版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/glw0223/article/details/88833394
分析
- 这个题真正的意思是:你知道第二天的价格和第一天的价格,如果是相减是挣钱的,就买。这题真是无语了。
class Solution {
public:
int maxProfit(vector<int>& prices) {
int result = 0;
if (prices.empty()) return result;
for (unsigned int i = 0; i < prices.size() - 1; ++i)
{
if (prices[i] < prices[i+1])
result += prices[i+1] - prices[i];
}
return result;
}
};