子树判断
来源:互联网 发布:麦淘网源码 编辑:程序博客网 时间:2024/05/29 16:49
//遍历Tree1,查找与Tree2 root相同的节点 boolean HasSubtree(TreeNode root1, TreeNode root2){ boolean result = false; if(root1 != null && root2 != null){ if(root1.val == root2.val){ //查找到与Tree2 root相同的节点,接着判断二者是否具有相同结构 result = DoesTree1hasTree2(root1,root2); } if(result != true) result = HasSubtree(root1.left, root2); if(result != true) result = HasSubtree(root1.right, root2); } return result; } boolean DoesTree1hasTree2(TreeNode root1, TreeNode root2){ boolean lflag = false; boolean rflag = false; //Tree2结束 if(root2==null){ return true; } //Tree2有节点时候,Tree1还有,说明肯定不是包含关系 if(root1==null){ return false; } if(root1.val != root2.val){ return false; } else{ lflag = DoesTree1hasTree2(root1.left,root2.left); rflag = DoesTree1hasTree2(root1.right,root2.right); return lflag && rflag; } }
0 0
- 子树判断
- 子树判断
- 子树判断
- 判断子树
- 4-08:判断子树
- 二叉树子树判断
- 判断是否为子树
- 判断是否子树
- 判断子树问题
- 二叉树判断子树问题
- 4.7-判断是否为子树
- 二叉树判断子树问题
- 二叉搜索树判断子树相等
- 判断二叉树是否为子树
- 子树判断问题(百度笔试题)
- 判断一棵树是不是另外一棵树的子树
- C语言判断二叉树的子树
- 子树
- WPF:如何在工作线程中更新窗体的UI元素(Dispatcher机制)
- Shiro登录机制验证,自定义FormAuthenticationFilter
- Java与C#的区别
- String类型传递是值传递,char[]类型传递是引用传递
- URL传递中文乱码问题
- 子树判断
- ISO C++ forbids declaration of ‘Contack’ with no type [-fpermissive]
- SubClassWindow详解
- HelloJSP!——pageContext对象
- 动画animation
- IOS学的容易--XML的SAX解析
- 各种编程语言的深度学习库整理
- codeforces 448C C. Painting Fence(分治+dp)
- Cstring转int型问题(error C2664: “atoi”: 不能将参数 1 从“CString”转换为“const char *”))