add new solutions
This commit is contained in:
parent
ccb8b5673b
commit
58527849b2
6 changed files with 202 additions and 0 deletions
20
solutions/1/q104/solution.go
Normal file
20
solutions/1/q104/solution.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package q104
|
||||
|
||||
type TreeNode struct {
|
||||
Val int
|
||||
Left *TreeNode
|
||||
Right *TreeNode
|
||||
}
|
||||
|
||||
func md(d int, node *TreeNode) int {
|
||||
if node == nil {
|
||||
return d - 1
|
||||
}
|
||||
return max(md(d+1, node.Left), md(d+1, node.Right))
|
||||
}
|
||||
|
||||
func maxDepth(root *TreeNode) int {
|
||||
return md(1, root)
|
||||
}
|
||||
|
||||
var _ = maxDepth
|
||||
Loading…
Add table
Add a link
Reference in a new issue