Created
May 17, 2014 03:49
-
-
Save tomkaith13/9097c1fed9192deda69d to your computer and use it in GitHub Desktop.
leetcode Best Time to Buy and Sell Stock II
This file contains 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: | |
# @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