最大利润

const maxProfit = (arr = [7,1,5,3,4,6]) => {
    let profit = 0
    for(let i = 1; i < arr.length; i++){
        let pre = arr[i - 1]
        let cur = arr[i]
        if(cur > pre){
            profit += cur - pre
        }
    }
    return profit
}

  

posted @ 2023-01-28 21:23  671_MrSix  阅读(13)  评论(0编辑  收藏  举报