Moment For Technology

JSMS28- Determine whether binary tree B is a subtree of binary tree A - finger offer18*

Posted on Aug. 23, 2023, 9:47 p.m. by Ehsaan Yohannan
Category: The front end Tag: The front end algorithm

It's the subtree of a to determine whether b is a binary tree

Analysis: This problem is a little difficult, but not very difficult, mainly for the binary tree traversal master can start. This code is not tuned, after a period of time to tune again

Bool DoTree(tree *t1,tree *t2) {if(t1==NULLt2==NULL) {return true; bool DoTree(tree *t1,tree *t2) {if(t1==NULLt2==NULL) {return true; } if(t1==NULL) { return false; } if(t1-data! =t2-data) { return false; } return DoTree(t1-left,t2-left)DoTree(t1-right,t2-right); } bool SubTree(tree *t1,tree *t2) { bool ret=false; if(t1! =NULLt2! If (t1-data==t2-data) // If (t1- value==t2-value) {ret=DoTree(t1,t2); } if(! {ret=SubTree(t1-left, T2 -left); } if(! {ret=SubTree(t1-right, T2 -right); } } return ret; }Copy the code
Search
About
mo4tech.com (Moment For Technology) is a global community with thousands techies from across the global hang out!Passionate technologists, be it gadget freaks, tech enthusiasts, coders, technopreneurs, or CIOs, you would find them all here.