买卖股票的最佳时期II - 中等难度

*************

C++

topic: 122. 买卖股票的最佳时机 II - 力扣(LeetCode)

*************

Inspect the topic:

How's your weekend? Overtime work or meet friends, are all kinds of spending time, which we have only once. At very first, I always complained about the unreasonable works and unhealthy relationships. But now, I donnot wanna do it because it reminds me the unhapppy things while I have my own time. And I changed a lot those years. Sometimes I really enjoy the smoking moment because in the smoking period, maybe 3 - 5 minites, that's yours. No matter the working things, or the peoples, it is just you.I never buy a stock but maybe in this topic I will figure out the principle how to warn money from a stock. 

I have no idea about this topic. No familiar topics I've ever done.

Maybe the aesthetic of silance works? 

The gift of mine tells me that buy in when the price is low and sale it out when the price is high.

if price[i + 1] > price[i], benifit = price[i + 1] - price[i]

class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int profit = 0;
        for(int i = 0; i < prices.size() - 1; i++) {
            if(prices[i + 1] > prices[i]) {
                profit += prices[i + 1] - prices[i];
            }
        }
        return profit;
    }
};

I then have a think about it, why this work?

For mathematic, it is ez to understand: 

if i have the price:

 In groups of two, each group is monotonically increasing. That's the method.

Happy UR monday. 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值