https://leetcode.com/problems/balanced-binary-tree


Runtime: 8 ms, faster than 88.82% of C++ online submissions for Balanced Binary Tree.
Memory Usage: 21.1 MB, less than 26.47% of C++ online submissions for Balanced Binary Tree.


```cpp
#include <bits/stdc++.h>

using namespace std;

class Solution {
public:
    int max_level = 0;

    void count(TreeNode* node, int counting) {
      if (node != nullptr) {
        counting += 1;
        if (counting > max_level) {
          max_level = counting;
        }
        count(node->left, counting);
        count(node->right, counting);
      }
    }

    bool travel(TreeNode* node) {
      if (node != nullptr) {
        max_level = 0;
        count(node->left, 0);
        int a = max_level;

        max_level = 0;
        count(node->right, 0);
        int b = max_level;

        if (abs(a-b) > 1) {
          return false;
        }

        return travel(node->left) && travel(node->right);
      } else {
        return true;
      }
    }

    bool isBalanced(TreeNode* root) {
      //7:39
      return travel(root);
      //7:42
    }
};
```