Best Time to Buy and Sell Stock II

Problem Summary

(Write in your own words, not copied from LeetCode. This forces comprehension.)

Key Observations

(Patterns, constraints, or hints in the problem statement.)

Main Concepts Used

(Mark the CS concepts or algorithms used.)

Time & Space Complexity

Code

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        prev = None
        totalProfit = 0
        for price in prices:
            if prev != None and price > prev:
                profit = price - prev
                totalProfit += profit
            prev = price
        return totalProfit

Common Mistakes / Things I Got Stuck On