Skip to content

Instantly share code, notes, and snippets.

@cixuuz
Created October 15, 2017 22:02
Show Gist options
  • Save cixuuz/7c1276679523b012435f7a2007b0319a to your computer and use it in GitHub Desktop.
Save cixuuz/7c1276679523b012435f7a2007b0319a to your computer and use it in GitHub Desktop.
[122. Best Time to Buy and Sell Stock II] #leetcode
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