leetcode-剑指55-I-OK

address

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */

// 带着深度递归
int maxDepth(struct TreeNode* root){
	if(root == NULL)
		return 0;
	int max = 1;
	void taowa(struct TreeNode* one, int depth){ //自身的depth
		if(depth> max)
			max = depth;
		if(one->left)
			taowa(one->left, depth+1);
		if(one->right)
			taowa(one->right, depth+1);
	}
	taowa(root,1);
	return max;
}
posted @ 2021-01-22 20:08  RougeBW  阅读(29)  评论(0编辑  收藏  举报