MaxProfit【★★★★★】

 1         /// <summary>
 2         /// Solution
 3         /// 100/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         }

 

posted @ 2015-07-25 21:51  叫我霍啊啊啊  阅读(263)  评论(0编辑  收藏  举报