Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 87a51bc

Browse files
增加0100.相同的树go语言的递归解法
增加了0100.相同的树go语言的递归解法
1 parent c7c211c commit 87a51bc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

‎problems/0100.相同的树.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,26 @@ class Solution:
237237
return True
238238
```
239239
Go:
240+
> 递归法
241+
```go
242+
func isSameTree(p *TreeNode, q *TreeNode) bool {
243+
if p != nil && q == nil {
244+
return false
245+
}
246+
if p == nil && q != nil {
247+
return false
248+
}
249+
if p == nil && q == nil {
250+
return true
251+
}
252+
if p.Val != q.Val {
253+
return false
254+
}
255+
Left := isSameTree(p.Left, q.Left)
256+
Right := isSameTree(p.Right, q.Right)
257+
return Left && Right
258+
}
259+
```
240260

241261
JavaScript:
242262

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /