Divide & Conquer of JAVA


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

Log in to reply
 

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