릿코드 104 - 트리의 가장 깊은 층
# 재귀 버전 class Solution(object): def pre(self, node, count, depth): count += 1 if node.right: self.pre(node.right, count, depth) if node.left: self.pre(node.left, count, depth) if count > depth[0]: depth[0] = count def maxDepth(self, root): depth = [0] if root: self.pre(root, 0, depth) return depth[0] # iter 버전 class Solution(object): def maxDepth(self, root): stack = [(1, root)] maxDepth = 0 whi..
더보기