MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / isSameTree

Method isSameTree

Python/same_tree.py:16–22  ·  view source on GitHub ↗
(self, p: Optional[TreeNode], q: Optional[TreeNode])

Source from the content-addressed store, hash-verified

14# self.right = right
15class Solution:
16 def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool:
17 if not p and not q: #return true if both nodes are Null
18 return True
19 if not p or not q or p.val != q.val: #return false if any of the root is Null or value of both roots is not equal
20 return False
21
22 return self.isSameTree(p.left , q.left) and self.isSameTree(p.right, q.right)
23

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected