Complete, Beats 11% runtime, beats 42% memory
This commit is contained in:
parent
f2ae3fd549
commit
2a6b73a842
@ -3,17 +3,17 @@ def maxProfit(prices):
|
|||||||
:type prices: List[int]
|
:type prices: List[int]
|
||||||
:rtype: int
|
:rtype: int
|
||||||
"""
|
"""
|
||||||
lowest = min(prices)
|
profit = 0
|
||||||
if lowest == prices[len(prices)-1]:
|
|
||||||
print('no profit')
|
|
||||||
return 0
|
|
||||||
for i in range(len(prices)):
|
for i in range(len(prices)):
|
||||||
if lowest == prices[i]:
|
# print(i)
|
||||||
k = i+1
|
if i+1 == len(prices):
|
||||||
# print(f'k is {k}')
|
break
|
||||||
profit = max(prices[k:]) - lowest
|
if prices[i] < prices[i+1]:
|
||||||
print(profit)
|
# print(i)
|
||||||
return profit
|
# print('hit')
|
||||||
|
profit += prices[i+1] - prices[i]
|
||||||
|
# print(profit)
|
||||||
|
return profit
|
||||||
|
|
||||||
maxProfit([7,1,5,3,6,4])
|
maxProfit([7,1,5,3,6,4])
|
||||||
# maxProfit([7,6,4,3,1])
|
# maxProfit([7,6,4,3,1])
|
||||||
Loading…
Reference in New Issue
Block a user