class Solution:
def maxProfit(self, prices: List[int]) -> int:
profit = 0
for i, buy_price in enumerate(prices[:-1]):
for sell_price in prices[i:]:
trade_profit = sell_price - buy_price
if trade_profit > profit:
profit = trade_profit
return profit
class Solution:
def maxProfit(self, prices: List[int]) -> int:
profit = 0
for i, buy_price in enumerate(prices[:-1]):
trade_profit = sorted(prices[i:], reverse=True)[0] - buy_price
if trade_profit > profit:
profit = trade_profit
return profit
class Solution:
def maxProfit(self, prices: List[int]) -> int:
profit = 0
if prices:
buy_price = prices[0]
for price in prices[1:]:
trade_profit = price - buy_price
if price < buy_price:
buy_price = price
elif trade_profit > profit:
profit = trade_profit
return profit