1 /// <summary> 2 /// Solution 3 /// 通过率 100% 4 /// </summary> 5 /// <param name="A"></param> 6 /// <returns></returns> 7 public static int solution(int[] A) 8 { 9 int maxEndingHere = A[0]; 10 int maxSofar = A[0]; 11 for (int i = 1; i < A.Length; i++) 12 { 13 maxEndingHere = Math.Max(A[i], maxEndingHere + A[i]); 14 maxSofar = Math.Max(maxEndingHere, maxSofar); 15 } 16 return maxSofar; 17 }
时间: 2024-10-13 03:11:37