563. Binary Tree Tilt

public class Solution {
    int result = 0;
    
    public int findTilt(TreeNode root) {
        postOrder(root);
        return result;
    }
    
    private int postOrder(TreeNode root) {
        if (root == null) return 0;
        
        int left = postOrder(root.left);
        int right = postOrder(root.right);
        
        result += Math.abs(left - right);
        
        return left + right + root.val;
    }
}

相关文章:

  • 2021-12-28
  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2021-08-19
  • 2022-12-23
  • 2021-10-01
猜你喜欢
  • 2021-11-04
  • 2022-12-23
  • 2021-07-04
  • 2022-12-23
相关资源
相似解决方案