From 7c0d640882e16ec7ff8be5f7c1655be7c22af91c Mon Sep 17 00:00:00 2001 From: LiangDazhu <42199191+LiangDazhu@users.noreply.github.com> Date: Thu, 13 May 2021 23:27:38 +0800 Subject: [PATCH] =?UTF-8?q?Update=200122.=E4=B9=B0=E5=8D=96=E8=82=A1?= =?UTF-8?q?=E7=A5=A8=E7=9A=84=E6=9C=80=E4=BD=B3=E6=97=B6=E6=9C=BAII.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added python version code --- problems/0122.买卖股票的最佳时机II.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/problems/0122.买卖股票的最佳时机II.md b/problems/0122.买卖股票的最佳时机II.md index 1a9b4f7f..61954ce2 100644 --- a/problems/0122.买卖股票的最佳时机II.md +++ b/problems/0122.买卖股票的最佳时机II.md @@ -138,7 +138,14 @@ Java: Python: - +```python +class Solution: + def maxProfit(self, prices: List[int]) -> int: + result = 0 + for i in range(1, len(prices)): + result += max(prices[i] - prices[i - 1], 0) + return result +``` Go: