leetcode 之 Same Tree

1、题目描述

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

Two binary trees are considered the same if they are structurally identical and the nodes have the same value.

给定两个二叉树,判断两个二叉树是否相同。

3、代码

 1  bool isSameTree(TreeNode* p, TreeNode* q) {
 2         
 3         if( p == NULL || q == NULL ) return ( p == q );
 4       
 5         if( p->val == q->val && isSameTree(p->left,q->left)  && isSameTree(p->right,q->right) )
 6             return true;
 7         else
 8             return false;
 9      
10     }
pp
原文地址:https://www.cnblogs.com/wangxiaoyong/p/8746699.html