public static int function(int[] array) { int cur = array[0]; int max = array[0]; for (int i = 1; i < array.length; i++) { cur = cur < 0 ? 0 : cur; cur += array[i]; max = Math.max(max, cur); } return max; }
public static int function(int[] array) { int cur = array[0]; int max = array[0]; for (int i = 1; i < array.length; i++) { cur = cur < 0 ? 0 : cur; cur += array[i]; max = Math.max(max, cur); } return max; }