munch2024 / munch

2 stars 11 forks source link

Documentation: Task 2.2 #120

Closed Fabrizv closed 8 months ago

Fabrizv commented 8 months ago

This code is from my LeetCode. It gives you an array and makes you figure out when would be he best day to buy for cheap and sell to gain the most money.

Goals:

  1. Add documentation to explain what the code does
  2. Add documentation to show what the arguments are
  3. Add documentation to five an example

Code Snippet:

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        left = 0
        right = 1
        max_profit = 0
        while right < len(prices):
            currProfit = prices[right] - prices[left]
            if prices[left] < prices[right]:
                max_profit = max(currProfit, max_profit)
            else:
                left = right
            right += 1
        return max_profit