Guest User

Untitled

a guest
Jun 22nd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. public static int maxPath(int[][] a, int row, int col) {
  2.     if(row<rows) { //while still more rows
  3.         if(max[row][col]>0) //we've found this subtree's max path before
  4.             return max[row][col]; //get it
  5.         else { //we've yet to find this subtree's max path
  6.             //set the max path for this subtree with the current value plus the
  7.             //greater of the left subtree's max path and the right subtree's max path
  8.             max[row][col]=a[row][col]+max(maxPath(a, row+1, col), maxPath(a, row+1, col+1));
  9.             return max[row][col]; //return the result
  10.         }
  11.     }
  12.     return 0; //end of triangle
  13. }
Add Comment
Please, Sign In to add comment