smj007

Best time to buy and sell stock II

Aug 31st, 2025
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.25 KB | None | 0 0
  1. class Solution:
  2.     def maxProfit(self, prices: List[int]) -> int:
  3.         max_profit = 0
  4.         for i in range(1, len(prices)):
  5.             if prices[i] > prices[i-1]:
  6.                 max_profit += prices[i] - prices[i-1]
  7.         return max_profit
Advertisement
Add Comment
Please, Sign In to add comment