From 68879e5e0e58dd4ec46b538d865ec51c09ec58fd Mon Sep 17 00:00:00 2001 From: bus710 Date: Mon, 17 Feb 2025 16:58:42 -0800 Subject: [PATCH] week11 --- maximum-depth-of-binary-tree/bus710.go | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 maximum-depth-of-binary-tree/bus710.go diff --git a/maximum-depth-of-binary-tree/bus710.go b/maximum-depth-of-binary-tree/bus710.go new file mode 100644 index 000000000..37026399c --- /dev/null +++ b/maximum-depth-of-binary-tree/bus710.go @@ -0,0 +1,28 @@ +package hello + +type TreeNode struct { + Val int + Left *TreeNode + Right *TreeNode +} + +func maxDepth(root *TreeNode) int { + if root == nil { + return 0 + } + return count(root) +} + +func count(node *TreeNode) int { + if node == nil { + return 0 + } + + lc := count(node.Left) + 1 + rc := count(node.Right) + 1 + + if lc > rc { + return lc + } + return rc +}