index
title: 二叉树的深度 date: 2019-08-21T11:00:41+08:00 draft: false categories: offer
题目
解题思路
public int TreeDepth(TreeNode root) {
int[] max = {0};
depth(root, max, 1);
return max[0];
}
private void depth(TreeNode root, int[] max, int curDepth) {
if (root == null) return;
if (curDepth > max[0]) max[0] = curDepth;
depth(root.left, max, curDepth + 1);
depth(root.right, max, curDepth + 1);
}Last updated