---
# System prepended metadata

title: '[LeetCode 104. Maximum Depth of Binary Tree]'
tags: [Leetcode]

---

# [LeetCode 104. Maximum Depth of Binary Tree]
###### tags: `Leetcode`
* 題目
    Given the root of a binary tree, return its maximum depth.

    A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
* 解法
    *   判斷左右子樹哪邊比較深
        1. 把比較深的那邊+1然後在return 
        2. fmax(double, double)這個可以比較兩參數的大小，並回傳大的那個
    *   停止條件 
        1. 當丟進來的tree是null，表示到最底部了

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


int maxDepth(struct TreeNode* root){
    if(!root)
        return 0;
    return 1+fmax(maxDepth(root->left),maxDepth(root->right));
}
```