leetcode-study

122. Best Time to Buy and Sell Stock II

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        """
        Calculate the maximum profit from a series of stock prices allowing unlimited transactions.
        
        Parameters:
            prices (List[int]): A list of stock prices where prices[i] is the price on the i-th day.
        
        Returns:
            int: The maximum profit achievable by summing all positive price differences.
        """
        total_profit = 0  # Accumulates the overall profit from transactions
        
        # Iterate from the second day onward, comparing each day's price with the previous day's price.
        for i in range(1, len(prices)):
            # Compute the profit by selling today and having bought yesterday.
            profit = prices[i] - prices[i - 1]
            # If the result is positive, it contributes to the overall profit.
            if profit > 0:
                total_profit += profit
        
        return total_profit

Summary of Techniques and Approaches: