首页 > 其他 > 详细

leetcode 之 Same Tree

时间:2018-04-08 19:18:13      阅读:193      评论:0      收藏:0      [点我收藏+]

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     }

 

leetcode 之 Same Tree

原文:https://www.cnblogs.com/wangxiaoyong/p/8746699.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!