Easy problem. Solve it elegantly.
Solution:
# T:O(n) S:O(h) class Solution: # @param root, a tree node # @return an integer def minDepth(self, root): if root is None: return 0 if root.left and root.right: return min(self.minDepth(root.left), self.minDepth(root.right)) + 1 else: return max(self.minDepth(root.left), self.minDepth(root.right)) + 1Run Time: 88 ms
No comments:
Post a Comment