```
if not root:
return 0
else:
l = [[root]]
while True:
temp = []
for node in l[-1]:
if not (node.left or node.right):
return len(l)
if node.left:
temp.append(node.left)
if node.right:
temp.append(node.right)
l.append(temp)
```