Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int KadaneWithIndices(int[] array){
- int currentMax = Integer.MIN_VALUE;
- int totalMax = Integer.MIN_VALUE;
- int startIndex = 0, endIndex = 0, tempIndex = 0;
- for(int i = 0; i < array.length; i++){
- currentMax += array[i];
- if(currentMax < 0){
- currentMax = 0;
- tempIndex = i + 1;
- }
- else if(totalMax < currentMax){
- totalMax = currentMax;
- startIndex = tempIndex;
- endIndex = i;
- }
- }
- System.out.println("Start index: " + startIndex + " End index: " + endIndex);
- return totalMax;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement