Skip to content
CodeItRaw
Code Reading
/
Tree Depth
Path
Play
Daily
Leaderboard
tr
Bug Hunt
Tree Depth
A one-node tree should have depth 1, but this says 2; it counts one too many on every tree. Find the line and the kind of bug.
Click the line you think is wrong.
1
def
depth
(node):
2
if
node
is
None
:
3
return
1
4
return
1
+
max
(depth(node.left), depth(node.right))