Skip to content

Instantly share code, notes, and snippets.

@tomkaith13
Created May 17, 2014 03:49
Show Gist options
  • Save tomkaith13/9097c1fed9192deda69d to your computer and use it in GitHub Desktop.
Save tomkaith13/9097c1fed9192deda69d to your computer and use it in GitHub Desktop.
leetcode Best Time to Buy and Sell Stock II
class Solution:
# @param prices, a list of integer
# @return an integer
def addr(self,x,y):
return (x + y)
def maxProfit(self, prices):
if not prices:
return 0
if len(prices) == 1:
return 0
profitList=[]
for i in range(len(prices) - 1):
#print i
#print profitLis
a = prices[i]
b = prices[i+1]
profitList.append((b - a))
#print profitList
posit = [x for x in profitList if x > 0]
if not posit:
return 0
#print posit
#print positive
return reduce(self.addr, posit)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment