Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. class Solution(object):
  2. def maxProfit(self, prices):
  3. """
  4. :type prices: List[int]
  5. :rtype: int
  6. """
  7. if not prices:
  8. return 0
  9. profit = 0
  10. min_val = prices[0]
  11.  
  12. for p in prices[1:]:
  13. if p > min_val:
  14. profit += p - min_val
  15. min_val = p
  16. else:
  17. min_val = p
  18. return profit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement