104. Maximum Depth of Binary Tree--LeetCode Record
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.
/**
* Definition for a binary tree node.
* public class TreeNode {
* public var val: Int
* public var left: TreeNode?
* public var right: TreeNode?
* public init(_ val: Int) {
* self.val = val
* self.left = nil
* self.right = nil
* }
* }
*/
class Solution {
func maxDepth(root: TreeNode?) -> Int {
if root == nil {
return 0
}
var leftCount:Int = maxDepth(root?.left)
var rightCount:Int = maxDepth(root?.right)
return leftCount > rightCount ? leftCount + 1 : rightCount + 1
}
}
相關文章
- 104. Maximum Depth of Binary Tree
- LeetCode 104. Maximum Depth of Binary TreeLeetCode
- 104. Maximum Depth of Binary Tree(圖解)圖解
- [leetcode]maximum-depth-of-binary-treeLeetCode
- 104-Maximum Depth of Binary Tree
- 111-Minimum Depth of Binary Tree
- 654-Maximum Binary Tree
- LeetCode のminimum-depth-of-binary-treeLeetCode
- 662-Maximum Width of Binary Tree
- 662. Maximum Width of Binary Tree
- leetcode-124-Binary Tree Maximum Path SumLeetCode
- LeetCode 124. Binary Tree Maximum Path SumLeetCode
- 7.79 DEPTH
- P3Depth: Monocular Depth Estimation with a Piecewise Planarity Prior3DMono
- RA-Depth: Resolution Adaptive Self-Supervised Monocular Depth EstimationAPTMono
- Java Concurrency in Depth - 1Java
- Java Concurrency in Depth - 2Java
- react-recordReact
- Active Record Associations
- screen-record
- E - Maximum Glutton
- ES6+ ---- record
- Daily record-SeptemberAI
- Learn and Record12
- Camera List Record - 120
- Binary Colouring
- [LeetCode] Third Maximum NumberLeetCode
- 實戰 Java 16 值型別 Record - 2. Record 的基本用法Java型別
- 104. 二叉樹的最大深度二叉樹
- Travel Notes-Record mood
- Homework record-Simple sorting
- Traversals of binary tree
- MySQL Binary LogMySql
- LeetCode 104.二叉樹的最大深度LeetCode二叉樹
- 1383. Maximum Performance of a TeamORM
- Cat, Fox and Maximum Array Split
- In-depth analysis of the comparison between AT and XA of distributed transactions
- BULK In-BIND與RECORD(轉)
- Renovation Tour-Record my home