增加0100.相同的树go语言的递归解法

增加了0100.相同的树go语言的递归解法
This commit is contained in:
SwaggyP
2022-08-20 09:53:47 +08:00
committed by GitHub
parent c7c211c30b
commit 87a51bcb69

View File

@ -237,6 +237,26 @@ class Solution:
return True
```
Go
> 递归法
```go
func isSameTree(p *TreeNode, q *TreeNode) bool {
if p != nil && q == nil {
return false
}
if p == nil && q != nil {
return false
}
if p == nil && q == nil {
return true
}
if p.Val != q.Val {
return false
}
Left := isSameTree(p.Left, q.Left)
Right := isSameTree(p.Right, q.Right)
return Left && Right
}
```
JavaScript