a python solution


  • 0
    R
            if len(prices)==0 or len(prices)==1:
                return 0
            buymin=prices[0]
            maxpft=0
            for i in range(1,len(prices)):  
                if prices[i]-buymin>maxpft:
                    maxpft=prices[i]-buymin
                if prices[i]<buymin:
                    buymin=prices[i]
            
            return maxpft
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.