MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / isSameTree

Function isSameTree

same_tree_100/solution.go:5–20  ·  view source on GitHub ↗
(p *TreeNode, q *TreeNode)

Source from the content-addressed store, hash-verified

3import . "github.com/austingebauer/go-leetcode/structures"
4
5func isSameTree(p *TreeNode, q *TreeNode) bool {
6 // if p is nil and q is not or vice versa
7 if (p == nil && q != nil) || (p != nil && q == nil) {
8 return false
9 }
10
11 // p and q are either both nil or both not nil
12 if p == nil && q == nil {
13 return true
14 }
15
16 // p and q are both not nil
17 return p.Val == q.Val &&
18 isSameTree(p.Right, q.Right) &&
19 isSameTree(p.Left, q.Left)
20}

Callers 1

Test_isSameTreeFunction · 0.85

Calls

no outgoing calls

Tested by 1

Test_isSameTreeFunction · 0.68