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
- Leetcode Maximum Depth of Binary TreeLeetCode
- [leetcode]maximum-depth-of-binary-treeLeetCode
- Leetcode-Maximum Depth of Binary TreeLeetCode
- Maximum Depth of Binary Tree leetcode javaLeetCodeJava
- 226. Invert Binary Tree--LeetCode RecordLeetCode
- Maximum Depth of Binary Tree 二叉樹的深度二叉樹
- 【LeetCode從零單排】No104 Maximum Depth of Binary TreeLeetCode
- 【LeetCode 104_二叉樹_遍歷】Maximum Depth of Binary TreeLeetCode二叉樹
- 100. Same Tree--LeetCode RecordLeetCode
- Leetcode Minimum Depth of Binary TreeLeetCode
- Leetcode-Minimum Depth of Binary TreeLeetCode
- Minimum Depth of Binary Tree leetcode javaLeetCodeJava
- LeetCode のminimum-depth-of-binary-treeLeetCode
- Leetcode Binary Tree Maximum Path SumLeetCode
- Binary Tree Maximum Path Sum leetcode javaLeetCodeJava
- leetcode-124-Binary Tree Maximum Path SumLeetCode
- LeetCode 124. Binary Tree Maximum Path SumLeetCode
- 【LeetCode 111_二叉樹_遍歷】Minimum Depth of Binary TreeLeetCode二叉樹
- [CareerCup] 4.4 Create List at Each Depth of Binary Tree 二叉樹的各層建立連結串列二叉樹
- P3Depth: Monocular Depth Estimation with a Piecewise Planarity Prior3DMono
- yebis error ---depth of fieldError
- RA-Depth: Resolution Adaptive Self-Supervised Monocular Depth EstimationAPTMono
- Java Concurrency in Depth - 1Java
- Java Concurrency in Depth - 2Java
- C# in Depth (Third Edition)C#
- react-recordReact
- linux find depth引數理解Linux
- Daily record-SeptemberAI
- oracle 9i dataguard 由MAXIMUM PERFORMANCE模式變為MAXIMUM PROTECTIONOracleORM模式
- 實戰 Java 16 值型別 Record - 2. Record 的基本用法Java型別
- Leetcode Maximum SubarrayLeetCode
- Algorithm for Maximum Subsequence Sum zGo
- pl/sql record 詳解SQL
- delete duplication record in sql serverdeleteSQLServer
- oracle plsql(一)_binary_float_binary_doubleOracleSQL
- LeetCode 104.二叉樹的最大深度LeetCode二叉樹