Best Time to Buy and Sell Stock (Leetcode 121)
Problem Link: https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
class Solution:
def maxProfit(self, prices: List[int]) -> int:
buyingprice=float('inf')
maxprofit=0
for i in prices:
buyingprice=min(buyingprice,i)
maxprofit=max(maxprofit,i-buyingprice)
return maxprofit
Last updated