算法题解

白天 夜间 首页 下载 阅读记录
  我的书签   添加书签   移除书签

122. Best Time to Buy and Sell Stock II

浏览 138 扫码 分享 2023-11-24 19:12:27

    LInk:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/

    贪心算法

    1. /**
    2. * @param {number[]} prices
    3. * @return {number}
    4. */
    5. var maxProfit = function(prices) {
    6. let len = prices.length;
    7. let total = 0;
    8. for(let i=0; i<len-1; i++){
    9. let differ = prices[i+1]-prices[i];
    10. if(differ>0) total+= differ;
    11. }
    12. return total;
    13. };

    若有收获,就点个赞吧

    0 人点赞

    上一篇:
    下一篇:
    • 书签
    • 添加书签 移除书签
    • 剑指offer
    • 贪心算法
    • Poj 2386-水洼问题
    • 部分和问题
    • 抽签问题
    • Poj 1852 - 蚂蚁🐜通过的最短时间和最长时间
    • 选择组成最大周长的三角形
    • 二叉树的前中后层序遍历
    • 回溯法
    • 排列树-39. Combination Sum
    • 排列树- 127-letter combinations of a phone number
    • 122. Best Time to Buy and Sell Stock II
    • 224-Basic-caculator
    • Longest Palindromic Substring
    暂无相关搜索结果!

      让时间为你证明

      展开/收起文章目录

      分享,让知识传承更久远

      文章二维码

      手机扫一扫,轻松掌上读

      文档下载

      请下载您需要的格式的文档,随时随地,享受汲取知识的乐趣!
      PDF文档 EPUB文档 MOBI文档

      书签列表

        阅读记录

        阅读进度: 0.00% ( 0/0 ) 重置阅读进度

          思维导图备注