MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / maxProfit

Method maxProfit

Array/BestTimeToBuyAndSellStockI_II.py:67–82  ·  view source on GitHub ↗

:type prices: List[int] :rtype: int

(self, prices)

Source from the content-addressed store, hash-verified

65# I
66class Solution(object):
67 def maxProfit(self, prices):
68 """
69 :type prices: List[int]
70 :rtype: int
71 """
72 if not prices:
73 return 0
74
75 mins = prices[0]
76 maxes = 0
77
78 for i in range(1, len(prices)):
79 mins = min(prices[i], mins)
80 maxes = max(prices[i]-mins, maxes)
81
82 return maxes
83
84# II
85class Solution(object):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected