CodePudding user response:
Def isSubtree (self, s, t) :"" "
: type s: TreeNode
T: : type TreeNode
Rtype: bool
"" "
Def isSameTree (p, q) :
If not p and not q:
Return True
Elif not p and q or (not q and p) :
Return False
The else:
If p.v al!=q.v al:
Return False
The else:
Return isSameTree (p.l eft, q.l eft) and isSameTree (p.r d.light, q.r d.light)
Prev=[s]
While prev:
The node=prev. Pop ()
If the node:
If isSameTree (node, t) :
Return True
Prev. The extend ([node. Left, node. The right])