Postorder traversal Java simple


  • 0
    L

    easy

    int tilt=0;
        public int findTilt(TreeNode root) {
            traverse(root);
            return tilt;
        }
        
        private int traverse(TreeNode root){
            if(root==null) return 0;
            int leftVal=traverse(root.left);
            int rightVal=traverse(root.right);
            tilt+=Math.abs(leftVal-rightVal);
            return root.val+leftVal+rightVal;
        }
    

Log in to reply
 

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