728x90
class Solution:
def maxProfit(self, prices: List[int]) -> int:
if not prices: return 0
sell_prc = max(prices)
max_prf = 0
for p in prices:
if p < sell_prc:
sell_prc = p # find the min value
max_prf = max(p - sell_prc, max_prf) # compare current profit with max profit
return max_prf
728x90
'Leetcode' 카테고리의 다른 글
70. Climbing Stairs (0) | 2020.08.15 |
---|---|
392. Is Subsequence (0) | 2020.08.15 |
1025. Divisor Game (0) | 2020.08.10 |
856. Score of Parentheses (0) | 2020.08.10 |
856. Score of Parentheses (0) | 2020.08.07 |
댓글