Java post order traversal


  • 0
        private int tilt = 0;
        private int sum(TreeNode root) {
            if (root == null) return 0;
            int l = sum(root.left), r = sum(root.right);
            tilt += Math.abs(l - r);
            return l+r+root.val;
        }
        public int findTilt(TreeNode root) {
            sum(root);
            return tilt;
        }
    

Log in to reply
 

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