LeetCode - Maximum Depth of Binary Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: int maxDepth(TreeNode* root) { if(!root) return 0; int left = maxDepth(root->left); int right = maxDepth(root->right); return max(left, right)+1; } };
相關推薦
LeetCode - Maximum Depth of Binary Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) :
[LeetCode] 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
LeetCode Maximum Depth of Binary Tree
Problem Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from
leetcode--maximum-depth-of-binary-tree(給定一棵二叉樹,找出它的最大深度)
給定一個二叉樹,找出其最大深度。 二叉樹的深度為根節點到最遠葉子節點的最長路徑上的節點數。 說明: 葉子節點是指沒有子節點的節點。 示例: 給定二叉樹 [3,9,20,null,null,1
[LeetCode]Maximum Depth of Binary Tree
java lee html net htm bin 版權 urn temp 版權聲明:本文為博主原創文章。未經博主同意不得轉載。 https://blog.csdn.net/yeweiou
[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
LeetCode演算法題-Maximum Depth of Binary Tree
這是悅樂書的第164次更新,第166篇原創 01 看題和準備 今天介紹的是LeetCode演算法題中Easy級別的第23題(順位題號是104)。給定二叉樹,找到它的最大深度。最大深度是從根節點到最遠葉節點的最長路徑上的節點數。葉子是沒有子節點的節點。 例如:給定二叉樹[3,9,20,null,null
[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)-
題目及用例 package pid104; /*二叉樹的最大深度 給定一個二叉樹,找出其最大深度。 二叉樹的深度為根節點到最遠葉子節點的最長路徑上的節點數。 說明: 葉子節點是指沒有子節點的節點。 示例: 給定二叉樹 [3,9,20,null,nul
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 / \
LeetCode 104.Maximum Depth of Binary Tree (二叉樹的最大深度)
題目描述: 給定一個二叉樹,找出其最大深度。 二叉樹的深度為根節點到最遠葉子節點的最長路徑上的節點數。 說明: 葉子節點是指沒有子節點的節點。 示例: 給定二叉樹 [3,9,20,null,null,15,7], 3 / \ 9 20 /
C#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
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
【leetcode】104.(Easy)Maximum Depth of Binary Tree
解題思路: bfs或dfs 提交程式碼:bfs class Solution { public int maxDepth(TreeNode root) { if(root==null) return 0; int
【LeetCode】maximum-depth-of-binary-tree
[程式設計題] maximum-depth-of-binary-tree 時間限制:1秒 空間限制:32768K Given a binary tree, find its maximum depth. The maximum depth is the numb
LeetCode(42) 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