MaxDoubleSliceSum【★★★★★】

 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             int[] arrStart = new int[A.Length];
10             int[] arrEnd = new int[A.Length];
11 
12             for (int i = 1; i < A.Length; i++)
13                 arrStart[i] = Math.Max(0, arrStart[i - 1] + A[i]);
14 
15             for (int i = A.Length - 2; i >= 0; i--)
16             {
17                 arrEnd[i] = Math.Max(0, arrEnd[i + 1] + A[i]);
18             }
19 
20             int maxValue = 0;
21             int temp = 0;
22 
23             for (int i = 1; i < A.Length - 1; i++)
24             {
25                 temp = arrStart[i - 1] + arrEnd[i + 1];
26                 maxValue = temp > maxValue ? temp : maxValue;
27             }
28 
29             return maxValue;
30         }

 

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