Last active
August 29, 2015 14:07
Revisions
-
alexandervasyuk revised this gist
Oct 3, 2014 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,7 @@ public static LinkedList<Integer> largestContinuousSum(int[] array) { if (array.length == 0) return null; LinkedList<Integer> current_path, max_path; int current_sum, max_sum; -
alexandervasyuk created this gist
Oct 3, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ public static LinkedList<Integer> largestContinuousSum(int[] array) { LinkedList<Integer> current_path, max_path; int current_sum, max_sum; max_path = current_path = new LinkedList<Integer>(); current_sum = max_sum = Integer.MIN_VALUE; for (int i : array) { if (current_sum < 0 && current_sum < i) { current_path = new LinkedList<Integer>(); current_path.add(i); current_sum = i; } else if (current_sum + i >= current_sum) { current_path.add(i); current_sum += i; } else { if (max_sum < current_sum) { max_path = current_path; max_sum = current_sum; current_path = new LinkedList<Integer>(); current_sum = 0; } } } if (current_sum > max_sum) { max_path = current_path; } return max_path; }