zoukankan      html  css  js  c++  java
  • 100. Same Tree

    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.

    题目含义:判断两个二进制树结构是否相等

     1     public boolean sameTree(TreeNode p, TreeNode q)
     2     {
     3         if (p==null && q==null) return true;
     4         if (p==null || q==null) return false;
     5         if (p.val != q.val) return false;
     6         return sameTree(p.left,q.left) && sameTree(p.right,q.right);
     7     } 
     8     public boolean isSameTree(TreeNode p, TreeNode q) {
     9         return sameTree(p,q);        
    10     }
  • 相关阅读:
    递归
    匿名函数
    迭代器、可迭代对象、生成器
    日期
    大文件读写
    面向对象
    魔术方法
    进程与线程
    numpy常用函数
    shell编程
  • 原文地址:https://www.cnblogs.com/wzj4858/p/7705259.html
Copyright © 2011-2022 走看看