Maximum Depth of Binary Tree Solutions in GoNumber 104Difficulty EasyAcceptance 66.1%Link LeetCodeOther languages C++, Java, PythonSolutionsGo solution by halfrost/LeetCode-Gopackage leetcode import ( "github.com/halfrost/LeetCode-Go/structures") // TreeNode definetype TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func maxDepth(root *TreeNode) int { if root == nil { return 0 } return max(maxDepth(root.Left), maxDepth(root.Right)) + 1} func max(a int, b int) int { if a > b { return a } return b}package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func maxDepth(root *TreeNode) int { if root == nil { return 0 } return max(maxDepth(root.Left), maxDepth(root.Right)) + 1 } func max(a int, b int) int { if a > b { return a } return b }