기억노트

[Leetcode/Python3] 121. Best Time to Buy and Sell Stock 본문

Coding Test 준비/Leetcode

[Leetcode/Python3] 121. Best Time to Buy and Sell Stock

진바니 2022. 1. 11. 02:58

Code

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        minv = prices[0]
        res = 0
        for x in prices[1:]:
            minv = min(minv, x)
            res = max(x - minv, res)
        return res

Result

Runtime: 1088 ms
Memory Usage: 25.2 MB

'Coding Test 준비 > Leetcode' 카테고리의 다른 글

[Leetcode/Python3] 70. Climbing Stairs  (0) 2022.01.11