```
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def isBalanced(self, root):
"""
:type root: TreeNode
:rtype: bool
"""
def isB(N, L=0):
if not N: return L
LL= isB(N.left, L+1)
RL = isB(N.right, L+1)
return max(LL,RL), abs(LL-RL) <= 1 and LB and RB
return isB(root)[1]
```