Created
October 15, 2017 22:02
-
-
Save cixuuz/7c1276679523b012435f7a2007b0319a to your computer and use it in GitHub Desktop.
[122. Best Time to Buy and Sell Stock II] #leetcode
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
class Solution(object): | |
# O(n) O(1) | |
def maxProfit(self, prices): | |
""" | |
:type prices: List[int] | |
:rtype: int | |
""" | |
# result placeholder | |
max_profit = 0 | |
# loop prices | |
for pre, cur in zip(prices[:-1], prices[1:]): | |
if pre < cur: | |
max_profit += cur - pre | |
# return | |
return max_profit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment