Maximum Depth of Binary Tree
回答のアプローチは Recursive DFS BFS Iterative DFS Base case root が empty children が Null Recursive DFS Time complexity: O(n) Mem complexity: O(n) class Solution(object): def maxDepth(self, root): """ :type root: TreeNode :rtype: int """ if not root: return 0 return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right)) BFS BFS を使う場合は Queue を使う。 3 / \ 9 20 /\ 15 7 | 3 | 9 | 20 | 15 | 7 | 1 2 2 3 3 ← Level...