/**
* 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 p=q;
return(p.val==q.val && isSameTree(p.left,q.left) && isSameTree(p.right,q.right));
}
}

  

100. Same Tree(Tree)的更多相关文章

  1. Leetcode算法刷题:第100题 Same Tree

    Same Tree 题目 给予两棵二叉树,判断这两棵树是否相等(即各节点的值都一样) 解题思路 分别遍历两棵二叉树,并用列表分别存储这两棵树的节点的值,比较这两个列表就可以了 class Soluti ...

  2. 100. Same Tree (Tree;DFS)

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...

  3. LeetCode(100)题解--Same Tree

    https://leetcode.com/problems/same-tree/ 题目: Given two binary trees, write a function to check if th ...

  4. LeetCode(100) Same Tree

    题目 Given two binary trees, write a function to check if they are equal or not. Two binary trees are ...

  5. [LeetCode]题100:Same Tree

    Given two binary trees, write a function to check if they are the same or not. Two binary trees are ...

  6. leetcode@ [236] Lowest Common Ancestor of a Binary Tree(Tree)

    https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/ Given a binary tree, find the ...

  7. LeetCode :: Convert Sorted Array (link list) to Binary Search Tree [tree]

    1.Given an array where elements are sorted in ascending order, convert it to a height balanced BST. ...

  8. 98. Validate Binary Search Tree (Tree; DFS)

    Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ...

  9. 101. Symmetric Tree (Tree, Queue; DFS, WFS)

    Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...

随机推荐

  1. Linux 实现自动安装服务组件以及优化内核参数 (转)

    安装好Linux裸机后(安装请参考:http://blog.itpub.net/26230597/viewspace-1380155/),还需要在其上安装一些基础组件,一般是手动一个个安装,比较繁复也 ...

  2. openstack(liberty): 简单网络连接图

    openstack起初的网络部分是和计算核心nova合在一起的,后来被拆分出来,独立成为一个模块, 现在名为Neutron. 本博文是学习记录,记录的是基于GRE tunnel技术的neutron和计 ...

  3. scala pattern matching

    scala语言的一大重要特性之一就是模式匹配.在我看来,这个怎么看都很像java语言中的switch语句,但是,这个仅仅只是像(因为有case关键字),他们毕竟是不同的东西,switch在java中, ...

  4. PhoneGap原理分析

    PhoneGap提供了Native Api的支持(如:重力感应.相机.联系人.文件.地址位置…), 比如要用js获取本机的联系人,可以用: var options = new ContactFindO ...

  5. PHP基础学习笔记(一)

    1.初步了解PHP+ php是一种运行在服务端的跨平台的脚本语言. + php语法: <?php echo "welcome!": ?> php像javascript语 ...

  6. LintCode "Max Tree"

    Something new I learnt from it: what is Treap and a O(n) construction https://en.wikipedia.org/wiki/ ...

  7. android学习笔记31——ADB命令

    使用Adb shell command直接送key event給Androidadb shell input keyevent 7 # for key '0'adb shell input keyev ...

  8. 战胜忧虑<4>——让平均概率来替你分忧

    让平均概率来替你分忧. 我们可以根据事情发生的平均率来评估我们的忧虑究竟值不值,如此一来,我想你和我应该可以去除99%的忧虑. 故事 我从小生长在密苏里州的一个农场,有一天,正帮妈妈采摘樱桃的时候,我 ...

  9. linux截图工具scrot

    SCROT截图工具 安装命令 sudo apt-get install scrot 截图命令使用说明: 1.抓取整个桌面:    scrot   ~/Pictures/pic1.jpg2.抓取窗口:  ...

  10. mysql 常用操作(整理)

    原文地址:http://blog.csdn.net/lxh090821/article/details/9410943 1       登录数据库 格式: mysql -h主机地址 -u用户名 -p用 ...