subject : Given binary tree , Returns the maximum depth of a binary tree
Ideas :BFS
Code :
class Solution:
def func(self , root):
if not root:
return None , 0
queue = []
queue.append((root , 1))
d = 0
while queue:
vertex , d ,min_d= queue.pop(0)
if vertex.left:
queue.append((vertex.left , d+1 ))
if vertex.right:
queue.append((vertex.right , d+1))
return d