[LeetCode] 122. 买卖股票的最佳时机 II

Posted 怕什么

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[LeetCode] 122. 买卖股票的最佳时机 II相关的知识,希望对你有一定的参考价值。

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

 

以上是关于[LeetCode] 122. 买卖股票的最佳时机 II的主要内容,如果未能解决你的问题,请参考以下文章

Leetcode 122 买卖股票的最佳时机

LeetCode第122题—买卖股票的最佳时机II—Python实现

Leetcode-122. 买卖股票的最佳时机 II

[LeetCode] 122. 买卖股票的最佳时机 II

LeetCode122.买卖股票的最佳时机II

LeetCode 122.买卖股票的最佳时机II