leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0563.cpp (387B)
0 class Solution {
1 int res = 0;
3 int sum_adding_tilt(TreeNode *root) {
4 if (!root) return 0;
5 int l = sum_adding_tilt(root->left);
6 int r = sum_adding_tilt(root->right);
7 res += abs(l - r);
8 return l + r + root->val;
9 }
11 public:
12 int findTilt(TreeNode *root) {
13 res = 0;
14 sum_adding_tilt(root);
15 return res;
16 }
17 };