[Leetcode] 121. Best Time to Buy and Sell Stock
1930 ワード
問題のショートカット
class Solution:
def maxProfit(self, prices: List[int]) -> int:
minSoFar = prices[0]
maxProfitSoFar = 0
for price in prices:
if minSoFar > price:
minSoFar = price
continue
if maxProfitSoFar < price - minSoFar:
maxProfitSoFar = price - minSoFar
return maxProfitSoFar
Reference
この問題について([Leetcode] 121. Best Time to Buy and Sell Stock), 我々は、より多くの情報をここで見つけました https://velog.io/@haebin/Leetcode-121.-Best-Time-to-Buy-and-Sell-Stockテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol