码迷,mamicode.com
首页 > 其他好文 > 详细

MaxProfit【看答案了】【★★★★★】

时间:2015-07-25 22:43:55      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

 1         /// <summary>
 2         /// Solution
 3         /// 通过率 100%
 4         /// </summary>
 5         /// <param name="A"></param>
 6         /// <returns></returns>
 7         public int solution(int[] A)
 8         {
 9             if (A.Length <= 1)
10                 return 0;
11             int minPrice = A[0];
12             int maxProfitSofar = 0;
13             for (int i = 1; i < A.Length; i++)
14             {
15                 maxProfitSofar = Math.Max(maxProfitSofar, A[i] - minPrice);
16                 minPrice = Math.Min(minPrice, A[i]);
17             }
18             return maxProfitSofar;
19         }

 

MaxProfit【看答案了】【★★★★★】

标签:

原文地址:http://www.cnblogs.com/HuoAA/p/4676666.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!