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:
Add documentation to explain what the code does
Add documentation to show what the arguments are
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
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:
Code Snippet: