{2, -5, 6, -1, 4, -10, 2, 3, -2, 5, -1, 2, -4, 3,1} // the array that causes the issue
< /code>
public int[] maxSubArray(int[] arr){
int currentMax = arr[0];
int currentIndex = 0;
int max = arr[0];
int startIndex = 0;
for(int i = 1; i < arr.length; i++){
if(arr > currentMax + arr){
startIndex = i;
}
currentMax = Math.max(currentMax + arr, arr);
if (currentMax > max){
currentIndex = i;
}
max = Math.max(currentMax, max);
}
return Arrays.copyOfRange(arr, startIndex, currentIndex + 1);
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... eption-6-5