Last active
April 5, 2020 21:40
-
-
Save munguial/7ba713fdf69a83bdb765aaa27497c67c to your computer and use it in GitHub Desktop.
Day 5 - Best time to buy and sell stock II
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3287/ | |
class Solution: | |
def maxProfit(self, prices: List[int]) -> int: | |
profit = 0 | |
for i in range(1, len(prices)): | |
if prices[i] > prices[i- 1]: | |
profit += prices[i] - prices[i - 1] | |
return profit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment