helper will return sum of a subtree.

int res = 0; public int findTilt(TreeNode root) { helper(root); return res; } int helper(TreeNode root){ if(root == null) return 0; int l = helper(root.left); int r = helper(root.right); res += Math.abs(l - r); return l + r + root.val; }Subcategories

LeetCode Weekly Contest 29