프로그래밍/LeetCode
[LeetCode][Python3] 121. Best Time to Buy and Sell Stock
snoopybox
2018. 9. 27. 01:04
Problem :
https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/
My Solution :
class Solution:
def maxProfit(self, prices):
"""
:type prices: List[int]
:rtype: int
"""
profit = 0
low = float('inf')
for p in prices:
profit = max(profit, p - low)
low = min(low, p)
return profit