PostOrder JavaScript Soluton


  • 1
    var diameterOfBinaryTree = function(root) {
      let max = 0;
      function postOrder(root) {
        if (root === null) {
          return 0;
        }
        const left = postOrder(root.left);
        const right = postOrder(root.right);
        let path = left + right;
        if (max < path) {
          max = path;
        }
        return Math.max(left+1, right+1);
      }
      postOrder(root);
      return max;
    };

Log in to reply
 

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