Download Best Time to Buy and Sell Stock.py
class Solution(object): def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ length = len(prices) if length == 0: return 0 max_profit, low = 0, prices for i in range(1, length): if low > prices[i]: low = prices[i] else: temp = prices[i] - low if temp > max_profit: max_profit = temp return max_profit
Leetcode 121 Best Time to Buy and Sell Stock problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.
Feedback is the most important part of any website.
If you have any query, suggestion or feedback, Please feel free to contact us.