mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
增加0100.相同的树go语言的递归解法
增加了0100.相同的树go语言的递归解法
This commit is contained in:
@ -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:
|
||||
|
||||
|
Reference in New Issue
Block a user