Friday, September 26, 2014

Minimum Depth of Binary Tree

Problem

Given a binary tree, find its minimum depth.

The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

Idea

DFS 遍历树, 方法是用栈,压入root,1。 然后每次都先弹出然后压入其left和right。

Note

  • 如何制作一个pair压入栈中

  • Solution


    No comments:

    Post a Comment