JavaScript Recursive Solution


  • 0
    var findTilt = function(root) {
      let tilt = 0;
      function postOrder(root) {
        if (root === null) {
          return 0;
        }
        let left = postOrder(root.left);
        let right = postOrder(root.right);
        tilt += Math.abs(left - right);
        return root.val + left + right;
      }
      postOrder(root);
      return tilt;
    };

Log in to reply
 

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