1. Code
class Solution:
def maxProfit(self, prices: List[int]) -> int:
profit = 0
#If the next price is larger than the current price, add the next price minus the current price.
for i in range(len(prices)-1):
if prices[i+1] > prices[i]:
profit += prices[i+1] - prices[i]
return profit
2. Result
Runtime : 48 ms(98.83%), Memory usage : 15.2 MB(9.27%)
(Runtime can be different by a system even if it is a same code.)