LeetCode之100. Same Tree

------------------------------------------
递归比较即可
AC代码:
/**
* 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;
else if((p==null && q!=null) || (p!=null && q==null) || (p!=null && q!=null && p.val!=q.val)) return false;
else return isSameTree(p.left,q.left) && isSameTree(p.right,q.right);
}
}
题目来源: https://leetcode.com/problems/same-tree/
LeetCode之100. Same Tree的更多相关文章
- Leetcode 笔记 100 - Same Tree
题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or ...
- 【一天一道LeetCode】#100. Same Tree(100题大关)
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given t ...
- 【LeetCode】100. Same Tree 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 [LeetCode] 题目地址:https:/ ...
- 【LeetCode】100 - Same Tree
Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...
- LeetCode OJ 100. Same Tree
Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...
- 【LeetCode】100. Same Tree (2 solutions)
Same Tree Given two binary trees, write a function to check if they are equal or not. Two binary tre ...
- <LeetCode OJ> 100. Same Tree
100. Same Tree Total Accepted: 100129 Total Submissions: 236623 Difficulty: Easy Given two binary tr ...
- LeetCode Javascript实现 100. Same Tree 171. Excel Sheet Column Number
100. Same Tree /** * Definition for a binary tree node. * function TreeNode(val) { * this.val = val; ...
- LeetCode 100. Same Tree (判断树是否完全相同)
100. Same Tree Given two binary trees, write a function to check if they are the same or not. Two bi ...
随机推荐
- 【IIS】iis6.1下添加两个ftp站点,
1,添加本地账户或密码||组 :[控制面板-->管理工具-->计算机管理器-->系统工具-->本地用户和组] 2,IIS站点目录先(添加FTP站点)[注意:多个站点多个端口] ...
- 【JavaScript】冒泡排序,字符串排序,数字排序
原理:是临近的数字两两进行比较,按照从小到大或者从大到小的顺序进行交换, function bubbleClick() { var str = "50,1,4,6,9,76,43,22,2, ...
- asp.net mvc HandleErrorAttribute 异常错误处理 无效!
系统未知bug,代码没有深究. 现象:filters.Add(new HandleErrorAttribute()); 使用了全局的异常处理过滤. HandleErrorAttribute 核心代码: ...
- Android LitePal 神一般的数据库框架 超级好用
参考: Android数据库高手秘籍(一)--SQLite命令 Android数据库高手秘籍(二)--创建表和LitePal的基本用法 Android数据库高手秘籍(三)--使用LitePal升级表 ...
- Delphi 实现数字转大写
从网上找的一段代码 /// <summary> /// 小写转大写 /// </summary> /// <param name="mmje"> ...
- fedora22切换用户windows分区不能自动挂载
新建立一个用户后,然后登陆后,再次登出,登陆原来的账户windows分区不能自动挂载
- 10月25日上午PHP继承多态
概念:子类可以继承父类的一切 方法重写:在子类里面对父类的方法进行重写,实现自己独特的功能.特点:单继承:一个子类只能有一个父类,一个父类可以派生出多个子类.override重写(子类对父类的重写) ...
- 面试题目——《CC150》中等难题
面试题17.1:编写一个函数,不用临时变量,直接交换两个数. 思路:使用差值或者异或 package cc150.middle; public class Exchange { public stat ...
- jQuery验证控件jquery.validate.js使用说明
官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation jQuery plugin: Validation 使用说明 转载 ...
- 大熊君JavaScript插件化开发------(实战篇之DXJ UI ------ Tab功能扩展完结版)
一,开篇分析 Hi,大家好!大熊君又和大家见面了,还记得上一篇文章吗.主要讲述了一个“Tab”插件是如何组织代码以及实现的”,以及过程化设计与面向对象思想设计相结合的方式是 如何设计一个插件的,两种方 ...