示例#1
0
        static void Main(string[] args)
        {
            tree tree = new tree(1)
            {
                left = new tree(2)
                {
                    left = new tree(3)
                    {
                        left = new tree(4), right = new tree(5)
                    }
                }, right = new tree(6)
                {
                    left = new tree(7), right = new tree(8)
                }
            };
            solution solution = new solution();

            Console.WriteLine(solution.MaxDepth(tree));
            Console.Read();
        }
示例#2
0
 public int MaxDepth(tree root)
 {
     return(root == null ? 0 : (Math.Max(MaxDepth(root.left), MaxDepth(root.right)) + 1));
 }