Skip to content

Latest commit

 

History

History

122-BestTimetoBuyandSellStockII

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Best Time to Buy and Sell Stock II

Problem can be found in here!

def maxProfit(prices: List[int]) -> int:
    max_profit = 0
    for i in range(1, len(prices)):
        if prices[i]-prices[i-1] > 0:
            max_profit += prices[i]-prices[i-1]

    return max_profit

Time Complexity: O(n), Space Complexity: O(1)