Lintcode469-Same Tree-Easy
469. Same Tree
Check if two binary trees are identical. Identical means the two binary trees have the same structure and every identical position has the same value.
Example
Example 1:
Input:{1,2,2,4},{1,2,2,4}
Output:true
Explanation:
       1             1
       / \           / \
      2   2   and   2   2
     /             /
    4             4
are identical.
Example 2:
Input:{1,2,3,4},{1,2,3,#,4}
Output:false
Explanation:
       1             1
       / \           / \
      2   3   and   2   3
     /               \
    4                 4
are not identical.
/**
* Definition of TreeNode:
* public class TreeNode {
* public int val;
* public TreeNode left, right;
* public TreeNode(int val) {
* this.val = val;
* this.left = this.right = null;
* }
* }
*/ public class Solution {
/**
* @param a: the root of binary tree a.
* @param b: the root of binary tree b.
* @return: true if they are identical, or false.
*/
public boolean isIdentical(TreeNode a, TreeNode b) {
if (a == null && b == null) {
return true;
}
else if (a != null && b !=null) {
return a.val == b.val
&& isIdentical(a.left, b.left)
&& isIdentical(a.right, b.right);
}
else {
return false;
}
}
}
Lintcode469-Same Tree-Easy的更多相关文章
- UVA12569-Planning mobile robot on Tree (EASY Version)(BFS+状态压缩)
		
Problem UVA12569-Planning mobile robot on Tree (EASY Version) Accept:138 Submit:686 Time Limit: 300 ...
 - Leetcode之101. Symmetric Tree Easy
		
Leetcode 101. Symmetric Tree Easy Given a binary tree, check whether it is a mirror of itself (ie, s ...
 - 【leetcode】Minimum Depth of Binary Tree (easy)
		
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
 - 【leetcode】Convert Sorted Array to Binary Search Tree (easy)
		
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 有序 ...
 - Leetcode 4.28 Tree Easy
		
1. 101. Symmetric Tree 用递归. class Solution { public boolean isSymmetric(TreeNode root) { if( root == ...
 - Leetcode 226. Invert Binary Tree(easy)
		
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia:This problem was ...
 - Leetcode 101. Symmetric Tree(easy)
		
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
 - Leetcode--572. Subtree of Another Tree(easy)
		
Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and no ...
 - 93. Balanced Binary Tree [easy]
		
Description Given a binary tree, determine if it is height-balanced. For this problem, a height-bala ...
 - LeetCode: 669 Trim a Binary Search Tree(easy)
		
题目: Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so th ...
 
随机推荐
- weblogic反序列化漏洞CVE-2018-2628-批量检测脚本
			
#coding=utf-8 import socket import time import re,os,sys,codecs type = 'utf-8' reload(sys) sys.setde ...
 - 解决vue单页路由跳转后scrollTop的问题
			
作为vue的初级使用者,在开发过程中遇到的坑太多了.在看页面的时候发现了页面滚动的问题,当一个页面滚动了,点击页面上的路由调到下一个页面时,跳转后的页面也是滚动的,滚动条并不是在页面的顶部 在我们写路 ...
 - 学习 ASP.NET Core 2.1:集成测试中使用 WebApplicationFactory
			
WebApplicationFactory 是 ASP.NET Core 2.1 新特性 MVC functional test infrastructure 中带来的新东东,它封装了 TestSer ...
 - Linux学习5-CentOS安装Python3.6环境和pip3
			
前言 centos7 自带有 python,但是却是 python2 版本的 python,如果你想安装个python3怎么办呢? 如果直接删除python2的话,可能会引起其他的问题,因为有些东西是 ...
 - align-item 和 align-content的区别
			
align-content 和 align-items : 1:共同点:它们对齐方向为交叉轴 2:不同点:align-content 应用于为 多行 而 align-items:应用于单行.
 - [js]js设计模式-修改原型
			
参考 操作原型 - 给原型添加属性 - 方法1: Fn.prototype.sum=function{} - 方法2: Fn.prototype={} //constructor指向了Object的原 ...
 - 使用msf对tomcat测试
			
1.1 使用nmap命令对目标主机进行扫描.单击桌面空白处,右键菜单选择"在终端中打开". 1.2 在终端中输入命令"nmap –sV 192.168.1.3" ...
 - mysql----------利用navicat查看两个数据库之间的差异
 - CurrentHashMap、HashMap、HashTable的区别
			
HashTable 底层数组+链表实现,无论key还是value都不能为null,线程安全,实现线程安全的方式是在修改数据时锁住整个HashTable,效率低,ConcurrentHashMap做了相 ...
 - JavaWeb-----ServletConfig对象和servletContext对象
			
1.ServletConfig ServletConfig:代表当前Servlet在web.xml中的配置信息 String getServletName() -- 获取当前Servlet在web. ...