标签:false == class 深度 java node treenode turn highlight
1.求二叉树最大深度
public int maxDepth(TreeNode root) { if(root==null){ return 0; } return 1+Math.max(maxDepth(root.left),maxDepth(root.right)); }
2.求二叉树最小深度
int minDepth(TreeNode *root) { if(root == NULL) return false; if(root->left == NULL) return minDepth(root->right) + 1; if(root->right == NULL) return minDepth(root->left) + 1; int leftDepth = minDepth(root->left); int rightDepth = minDepth(root->right); return leftDepth < rightDepth ? (leftDepth + 1) : (rightDepth + 1); }
标签:false == class 深度 java node treenode turn highlight
原文地址:http://www.cnblogs.com/youza/p/7668599.html