104.Maximum_Depth_Of_Binary_Tree

二叉树最简单的性质之一,递归可得。
时间复杂度:O(N)
C++代码:

class Solution {
public:
	int maxDepth(TreeNode* root) {
		if (root == nullptr)
			return 0;
		return max(maxDepth(root->left), maxDepth(root->right)) + 1;
	}
};

猜你喜欢

转载自blog.csdn.net/qq_42263831/article/details/84259183