Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int maxPath(int[][] a, int row, int col) {
- if(row<rows) { //while still more rows
- if(max[row][col]>0) //we've found this subtree's max path before
- return max[row][col]; //get it
- else { //we've yet to find this subtree's max path
- //set the max path for this subtree with the current value plus the
- //greater of the left subtree's max path and the right subtree's max path
- max[row][col]=a[row][col]+max(maxPath(a, row+1, col), maxPath(a, row+1, col+1));
- return max[row][col]; //return the result
- }
- }
- return 0; //end of triangle
- }
Add Comment
Please, Sign In to add comment