This commit is contained in:
parent
b4561ecb99
commit
de7b15c917
1 changed files with 13 additions and 0 deletions
13
medium/best_time_to_buy_and_sell_stock_ii.py
Normal file
13
medium/best_time_to_buy_and_sell_stock_ii.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii
|
||||
|
||||
from typing import List
|
||||
|
||||
class Solution:
|
||||
def maxProfit(self, prices: List[int]) -> int:
|
||||
result = 0
|
||||
last = prices[0]
|
||||
for i in range(1, len(prices)):
|
||||
if last < prices[i]:
|
||||
result += prices[i] - last
|
||||
last = prices[i]
|
||||
return result
|
||||
Loading…
Add table
Add a link
Reference in a new issue