赞
踩
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
Subscribe to see which companies asked this question.
- /**
- * Definition for a binary tree node.
- * public class TreeNode {
- * int val;
- * TreeNode left;
- * TreeNode right;
- * TreeNode(int x) { val = x; }
- * }
- */
- public class Solution {
-
- public int maxDepth(TreeNode root)
- {
- int h = 0;
- if(root == null)
- {
- return h;
- }
- else
- {
- return 1+Math.max(maxDepth(root.left), maxDepth(root.right));
- }
-
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。