JasonChang

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

profit 可以累积

 1 public class Solution {
 2     public int maxProfit(int[] prices) {
 3         // IMPORTANT: Please reset any member data you declared, as
 4         // the same Solution instance will be reused for each test case.
 5         if(prices == null)
 6             return 0;
 7         int result = 0;
 8         for(int i = 1; i < prices.length; i++)
 9         {
10             if(prices[i] > prices[i-1])
11                 result += prices[i] - prices[i-1];
12         }
13         return result;
14     }
15 }

 

posted on 2013-11-07 13:05  JasonChang  阅读(159)  评论(0编辑  收藏  举报