LC 104. Maximum Depth of Binary Tree
1.題意
104. Maximum Depth of Binary Tree
Easy
98540
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
Note: A leaf is a node with no children.
Example:
Given binary tree [3,9,20,null,null,15,7]
3 / \ 9 20 / \ 15 7
return its depth = 3.
2.程式碼
class Solution { public: int maxDepth(TreeNode* root) { if(root==NULL) { return 0; } else return max(1 + maxDepth(root -> left), 1 + maxDepth(root -> right)); } };
相關推薦
LC.104. Maximum Depth of Binary Tree
take for ret pub left each http pac pan https://leetcode.com/problems/maximum-depth-of-binary-tree/description/Given a binary tree, find
LC 104. Maximum Depth of Binary Tree
1.題意 104. Maximum Depth of Binary Tree Easy 98540 Given a binary tree, find its maximum depth. The maximum depth is the number of nodes
[LeetCode] 104. Maximum Depth of Binary Tree Java
font from max clas [] 高度 java ret 使用 題目: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the
104. Maximum Depth of Binary Tree
rom cnblogs eno node efi maximum binary imu pan Given a binary tree, find its maximum depth. The maximum depth is the number of nodes al
104.Maximum Depth of Binary Tree
ons lin pan div .com private 分享 nbsp root 題目鏈接https://leetcode.com/submissions/detail/119156148/ 題目大意:返回一個二叉樹的高度。 法一:深搜,左右子樹直接遞歸(耗時1ms),代
104. Maximum Depth of Binary Tree C++ 答案
block 方法 int mat rst recursion off HERE space 104. Maximum Depth of Binary Tree -- Easy 方法 使用遞歸 /** * Definition for a binary tree node.
[LeetCode&Python] Problem 104. Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farth
LeetCode 104. Maximum Depth of Binary Tree (二叉樹的最大深度)
原題 Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the
LeetCode--104. Maximum Depth of Binary Tree
題目連結:https://leetcode.com/problems/maximum-depth-of-binary-tree/ 求樹的最大深度,一言以蔽之:子節點樹的最大深度加1就是父節點樹的最大深度。遞迴題目想通了就好簡單!!! class Solution { public i
Leetcode 104. Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long
LeetCode 104.Maximum Depth of Binary Tree (二叉樹的最大深度)
題目描述: 給定一個二叉樹,找出其最大深度。 二叉樹的深度為根節點到最遠葉子節點的最長路徑上的節點數。 說明: 葉子節點是指沒有子節點的節點。 示例: 給定二叉樹 [3,9,20,null,null,15,7], 3 / \ 9 20 /
JavaScript刷LeetCode -- 104. Maximum Depth of Binary Tree
一、題目 Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down
104 Maximum Depth of Binary Tree
題目來源:https://leetcode.com/problems/maximum-depth-of-binary-tree/submissions/ 自我感覺難度/真實難度:easy/easy 真的是第一次完全沒有看其他參考答案,第一次寫出來,而且沒有報錯,值得
leetcode 104 Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest
104. Maximum Depth of Binary Tree(1.private 2.void)
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthe
104. Maximum Depth of Binary Tree [easy] (Python)
題目連結 題目原文 Given a binary tree, find its maximum depth. The maximum depth is the number
[Lintcode]97. Maximum Depth of Binary Tree/[Leetcode]104. Maximum Depth of Binary Tree
input pre .com add rip like efi height find 97. Maximum Depth of Binary Tree/104. Maximum Depth of Binary Tree 本題難度: Easy Topic: Binary
leetCode 104.Maximum Depth of Binary Tree(二叉樹最大深度) 解題思路和方法
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down t
leetcode 104. Maximum Depth of Binary Tree 111. Minimum Depth of Binary Tree
treenode right left leetcode oot tco binary 判斷 root 104: class Solution { public: int maxDepth(TreeNode* root) { if(roo
leetcode-104-二叉樹的最大深度(maximum depth of binary tree)-
題目及用例 package pid104; /*二叉樹的最大深度 給定一個二叉樹,找出其最大深度。 二叉樹的深度為根節點到最遠葉子節點的最長路徑上的節點數。 說明: 葉子節點是指沒有子節點的節點。 示例: 給定二叉樹 [3,9,20,null,nul