[Leetcode] Best time to buy and sell stock ii

nerry·2022년 1월 20일
0

알고리즘

목록 보기
14/86

문제

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        profit=0
        for i in range(len(prices)-1):
            print(i)
            if prices[i]<prices[i+1]:
                profit+=prices[i+1]-prices[i]
        return profit

⬇️

pythonic

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        return(max(prices[i+1]-prices[i],0) for i in range(len(prices)-1))
profile
터벅터벅 개발(은좋은)자 로그

0개의 댓글