Recca Chao 的 gitHub page

推廣網站開發,包含 Laravel 和 Kotlin 後端撰寫、自動化測試、讀書心得等。Taiwan Kotlin User Group 管理員。

View on GitHub

Hi, here’s your problem today. This problem was recently asked by LinkedIn:

Given a binary tree, find the minimum depth of the binary tree. The minimum depth is the shortest distance from the root to a leaf.

Here’s an example and some starter code.

class Node: def init(self, value, left=None, right=None): self.value = value self.left = left self.right = right

def min_depth_bst(root):

Fill this in.

n3 = Node(3, None, Node(4)) n2 = Node(2, Node(3)) n1 = Node(1, n2, n3)

1

/ \

2 3

\

4

print(min_depth_bst(n1))

2