Question
Given the
root
of a binary tree, return its maximum depth.A binary tree’s maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
This is atree question.
Idea(s)
- BFS
- You could iterate layer by layer counting each layer as you go along
- Establish a queue
- Push root and None to queue
- While there are items in the que, add children, every time you see a None value, increment a layer counter, add another None to set up the next layer, if you see two consecutive Nones, return depth
- If the while loop breaks return depth