```
class Solution {
public:
int findTilt(TreeNode* root) {
int tilt = 0;
sum(root, tilt);
return tilt;
}
private:
int sum(TreeNode* node, int& tilt) {
if (!node) {
return 0;
}
int left = sum(node->left, tilt);
int right = sum(node->right, tilt);
tilt += abs(left - right);
return node->val + left + right;
}
};
```