Can someone help me figure out what's wrong with my code?
This test case doesn't work - [2,null,3,null,4,null,5,null,6] - my code returns 0 instead of 5. Not sure why.
class Solution:
def minDepth(self, root: TreeNode) -> int:
if root.left is None and root.right is None:
return 0
elif root.left is None and root.right is not None:
return self.minDepth(root.right)
elif root.right is None and root.left is not None:
return self.minDepth(root.left)
else:
return 1 + min(self.minDepth(root.left), self.minDepth(root.right))
Thank you!