LeetCode|Same Tree-java
来源:互联网 发布:虚拟专用网络 编辑:程序博客网 时间:2024/05/21 22:55
题目:
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.
思路:
判断两个二叉树是否相同,使用前序遍历,如果节点都为空或者两个节点的值相同则返回true,否则返回false
/** * 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) { if (p == null && q == null) { return true; } if (p != null && q != null && p.val == q.val) { return isSameTree(p.left, q.left) && isSameTree(p.right, q.right); } return false; }}
0 0
- [Leetcode] Same Tree (Java)
- LeetCode-Same Tree(java)
- Leetcode Same Tree Java
- [LeetCode][Java] Same Tree
- LeetCode|Same Tree-java
- (java)leetcode Same Tree
- leetcode:Same Tree 【Java】
- LeetCode 100 -Same Tree ( JAVA )
- leetcode-java-100. Same Tree
- [LeetCode-100]Same Tree(java)
- 【leetcode】100. Same Tree【java】
- LeetCode-100. Same Tree (Java)
- 【leetcode】Same Tree and Symmetric Tree-----Java
- Leetcode - Tree - Same Tree
- [leetcode][tree] Same Tree
- leetcode(java):100 Same Tree
- Leetcode:100. Same Tree (JAVA)
- [leetcode]100. Same Tree@Java解题报告
- IDF -PMC与Intel联手演示池化NVMe解决方案
- Android 常用第三方库(长期更新)
- mysql统计表中条目个数的方法举例
- centos7装linux翻译软件
- CEOI 1999 Parity game (并查集+离散化)
- LeetCode|Same Tree-java
- 成为程序员前需要做的10件事
- SELINUX 导致rsync无法同步文件
- [LeetCode-19] Remove Nth Node From End of List(删除倒数第N个节点)
- Maven学习笔记(四)——MyEclipse导入、创建&配置Maven工程
- jeecms各种标签类(大部分,并没有包含一些其他的如text_cut html_cut之类)
- LDAP概念和原理
- RobotFramework安装和配置说明
- C中结构体的存储分配