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


Runtime: 60 ms, faster than 39.82% of Python3 online submissions for Balanced Binary Tree.
Memory Usage: 18.3 MB, less than 52.79% of Python3 online submissions for Balanced Binary Tree.


```python
'''
def valid_check(node: TreeNode):
    """
    if node != None and node.left !=None and node.left.left !=None and node.left.left.left != None:
        return False
    if node != None and node.right !=None and node.right.right !=None and node.right.right.right != None:
        return False

    if node != None and node.left !=None and node.left.left !=None and node.right == None:
        return False
    if node != None and node.right !=None and node.right.right !=None and node.left == None:
        return False
    """
    """
    if node != None and node.left !=None and node.left.left !=None and (node.right == None and node.left.right == None):
        return False
    if node != None and node.right !=None and node.right.right !=None and (node.left == None and node.right.left == None):
        return False
    """
    """
    if node != None and node.left !=None and (node.left.left !=None or node.left.right != None) and (node.right == None and node.right.left == None and node.right.right == None):
        return False
    if node != None and node.right !=None and (node.right.right !=None or node.right.left != None) and (node.left == None and node.left.left == None and node.left.right == None):
        return False
    """

    return True

def trave(node: TreeNode):
    if (node != None):
        return valid_check(node.left) and valid_check(node.right) and trave(node.left) and trave(node.right)
    else:
        return True

class Solution:
    def isBalanced(self, root: TreeNode) -> bool:
        #6:15
        right = valid_check(root)
        if right:
            return trave(root)
        else:
            return False
        #6:18
        #debug until 7:07
'''
    
max_level = 0

def count(node: TreeNode, counting: int):
    global max_level
    if (node != None):
        counting += 1
        if counting > max_level:
            max_level = counting
        count(node.left, counting)
        count(node.right, counting)

def travel(node: TreeNode):
    global max_level
    if (node):
        max_level = 0
        count(node.left, 0)
        #print(max_level)
        a = max_level
        
        max_level = 0
        count(node.right, 0)
        #print(max_level)
        b = max_level
        
        #print(a,b)
        if abs(a-b) > 1:
            return False
        
        return travel(node.left) and travel(node.right)
    else:
        return True

class Solution:
    def isBalanced(self, root: TreeNode) -> bool:
        #6:15
        return travel(root)
        #6:18
        #debug until 7:07
        #redesign until 7:23
```