From 395bdd7509edbd0e7ee03908d347093e2d89e7e5 Mon Sep 17 00:00:00 2001 From: fusunx <1102654482@qq.com> Date: Thu, 27 May 2021 08:10:25 +0800 Subject: [PATCH] =?UTF-8?q?0122.=E4=B9=B0=E5=8D=96=E8=82=A1=E7=A5=A8?= =?UTF-8?q?=E7=9A=84=E6=9C=80=E4=BD=B3=E6=97=B6=E6=9C=BA.md=20Javascript?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0122.买卖股票的最佳时机II.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/problems/0122.买卖股票的最佳时机II.md b/problems/0122.买卖股票的最佳时机II.md index 2333eaff..4b878aa0 100644 --- a/problems/0122.买卖股票的最佳时机II.md +++ b/problems/0122.买卖股票的最佳时机II.md @@ -190,7 +190,17 @@ class Solution: Go: - +Javascript: +```Javascript +// 贪心 +var maxProfit = function(prices) { + let result = 0 + for(let i = 1; i < prices.length; i++) { + result += Math.max(prices[i] - prices[i - 1], 0) + } + return result +}; +``` ----------------------- * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)