MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / maxProfit

Method maxProfit

121 Leetcode/121 leetcode.py:2–10  ·  view source on GitHub ↗
(self, prices: List[int])

Source from the content-addressed store, hash-verified

1class Solution:
2 def maxProfit(self, prices: List[int]) -> int:
3 maxProfit = 0
4 currentMax = 0
5
6 for i in reversed(prices):
7 currentMax = max(currentMax, i)
8 profit = currentMax - i
9 maxProfit = max(profit, maxProfit)
10 return maxProfit

Callers

nothing calls this directly

Calls 1

maxFunction · 0.50

Tested by

no test coverage detected