Skip to content

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

Open
@swiftwind0405

Description

@swiftwind0405

方法一: 贪心算法

解题思想:

代码:

var maxProfit = function(prices) {
    let profit = 0;
    for (let i = 1; i < prices.length; i++) {
        if (prices[i] > prices[i - 1]) {
            profit += prices[i] - prices[i - 1];
        }
    }
    return profit;
};

复杂度分析:

  • 时间复杂度:
  • 空间复杂度:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions