100. Same Tree
来源:互联网 发布:女孩凉鞋淘宝 编辑:程序博客网 时间:2024/05/29 19:51
//本文内容来自StarSight,欢迎访问。
Given two binary trees, write a function to check if they are equal or not.
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public boolean isSameTree(TreeNode p, TreeNode q) { boolean l=false,r=false; if(p==null){ if(q==null) return true; else if(q!=null) return false; } if(q==null){ return false; } if(p.left!=null) l = isSameTree(p.left,q.left); else if(q.left==null) l = true; if(p.right!=null) r = isSameTree(p.right,q.right); else if(q.right==null) r = true; if(p.val==q.val&&l==true&&r==true) return true; return false; }}
依次遍历,没啥好说的。
0 0
- [LeetCode]100.Same Tree
- LeetCode 100. Same Tree
- 100.Same Tree
- 【LeetCode】100.Same Tree
- [Leetcode] 100. Same Tree
- [Leetcode] 100. Same Tree
- LeetCode --- 100. Same Tree
- LeetCode 100. Same Tree
- [leetcode] 100.Same Tree
- 100.Same Tree
- 100. Same Tree
- 100.Same Tree
- 100. Same Tree
- 100. Same Tree
- 100. Same Tree
- leetCode 100. Same Tree
- 100. Same Tree
- [LeetCode]100. Same Tree
- Android Realm数据库使用指南
- JavaScript小程序
- 菜鸡专用 react+webpack+webstorm环境搭建那点事儿
- Codeforces Round #237 (Div. 2) B
- automake编译.c文件最终总结
- 100. Same Tree
- 1111111111
- 父类与子类的静态代码块、代码块、构造方法执行顺序
- 公共子串
- 第一次建立属于自己的技术博客
- makefile参数
- 【最新】 树莓派3B 设置通用(UART)串口的方法
- 前端Cookie基本使用方法
- 345. Reverse Vowels of a String