1 题目

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.

Hide Tags

Tree Depth-first Search

 
2 思路
好久没做树的题目了,选了一道最简单的树的题目。看别人答案代码思路就很简单了,自己想,想半天思路并不是很好,各种漏洞。
参考:
3 代码
    public boolean isSameTree(TreeNode p,TreeNode q){
if (p == null || q == null) return (p == q);
return (p.val == q.val) && isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
}

[leet code 100] same tree的更多相关文章

  1. 【Leet Code】Palindrome Number

    Palindrome Number Total Accepted: 19369 Total Submissions: 66673My Submissions Determine whether an ...

  2. 100. Same Tree(C++)

    100. Same Tree Given two binary trees, write a function to check if they are equal or not. Two binar ...

  3. 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; ...

  4. Proxmox VE中出现TASK ERROR: command 'apt-get update' failed: exit code 100的解决方法

    问题描述: 出现这个错误一般在WEB或者在Proxmox VE的服务器上面能看到日志: PVE中出现TASK ERROR: command 'apt-get update' failed: exit ...

  5. 100.Same Tree(E)

    100. same tree 100. Same Tree Given two binary trees, write a function to check if they are the same ...

  6. <LeetCode OJ> 100. Same Tree

    100. Same Tree Total Accepted: 100129 Total Submissions: 236623 Difficulty: Easy Given two binary tr ...

  7. 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 ...

  8. Leet Code 771.宝石与石头

    Leet Code编程题 希望能从现在开始,有空就做一些题,自己的编程能力太差了. 771 宝石与石头 简单题 应该用集合来做 给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S  ...

  9. leetcode 100. Same Tree、101. Symmetric Tree

    100. Same Tree class Solution { public: bool isSameTree(TreeNode* p, TreeNode* q) { if(p == NULL &am ...

随机推荐

  1. linux上的工具或软件

    1.下载软件 yum install axelaxel http://mirror.cse.iitk.ac.in/archlinux/iso/2015.04.01/archlinux-2015.04. ...

  2. fastcgi协议解析(nginx)

    请求NGINX ->[ {(post data) +> (NGX_HTTP_FASTCGI_STDIN)} * N +> {(environment variables) +> ...

  3. centos下安装nodejs

    1.首先要安装gcc, # yum install libtool automake autoconf gcc-c++ openssl-devel 2.可以进入某个目录,下载NodeJS v0.10. ...

  4. 嵌入式操作系统VxWorks中网络协议存储池原理及实现

    嵌入式操作系统VxWorks中网络协议存储池原理及实现 周卫东 蔺妍 刘利强 (哈尔滨工程大学自动化学院,黑龙江 哈尔滨,150001) 摘  要  本文讨论了网络协议存储池的基本原理和在嵌入式操作系 ...

  5. DockerDesktop简单安装和使用

    一.在windows10下,安装DockerDesktop: 1.检查windows版本为企业版或专业版,并开启Hyper-v系统设置:电脑的控制面板->程序->启用或关闭Windows功 ...

  6. linux系统,在centos7环境下安装jdk步骤

    记录一下安装jdk1.8版本的出错过程: 按照这个博客内容安装的,以及修改文件权限博客 [Linux]CentOS7下安装JDK详细过程 [Linux]目录文件权限的查看和修改[转] 1.安装的jdk ...

  7. 【转】mysql查看表空间占用情况

    ${database} 为数据库的名称 /*1.查看索引 (1)单位是GB*/ SELECT CONCAT(ROUND(SUM(index_length)/(**), ), ' GB') AS 'To ...

  8. 2018.11.24 poj3415Common Substrings(后缀数组+单调栈)

    传送门 常数实在压不下来(蒟蒻开O(3)都过不了). 但有正确性233. 首先肯定得把两个字符串接在一起. 相当于heightheightheight数组被height<kheight<k ...

  9. 实战fortran77基础语法

    1.数组在主函数和子例行函数中传递 一个项目中有两个源代码文件: 代码: PROGRAM ARRAYZBL DOUBLE PRECISION A,B,C,D(:) INTEGER I DATA A,B ...

  10. vue中$route 和$router的区别

    在vue中会出现一种情况 const url=this.$route.query.returnURL; this.$router.push(url);    $router和$route的区别傻傻的分 ...