Post Order Traversal


  • 0
    K

    Re: Binary Tree largest Sum

    int maxDia = Integer.MINVALUE;
    int postOrder ( int[] tree , int index ) {

            if(index > tree.length -1)
                 return 0;
            
            int maxLeftBranch = postOrder(tree,index*2);
            int maxRightBranch = postOrder(tree,index*2 + 1);
            
            int dia = maxLeftBranch + maxRightBranch + tree[index];
            
            if(dia > maxDia)
              maxDia = dia;
            
            return Math.max(maxLeftBranch,maxRightBranch);
            
        }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.