Created
April 5, 2015 18:00
-
-
Save bluerogue/2ad2d587b42b340e79f1 to your computer and use it in GitHub Desktop.
Largest sum from adjacent path
This file contains 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 characters
Map<Integer, Integer[]> values = populate(); // should typically be a 2D array of type 'int' instead | |
for (int i = values.size() - 2; i >= 0; i--) { | |
for (int j = 0; j <= i; j++) { | |
values.get(i)[j] += | |
Math.max(values.get(i + 1)[j], values.get(i + 1)[j + 1]); | |
} | |
} | |
int largestPathSum = values.get(0)[0]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment