RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
leetCode100.SameTree树

100. Same Tree

创新互联公司主要为客户提供服务项目涵盖了网页视觉设计、VI标志设计、网络营销推广、网站程序开发、HTML5响应式成都网站建设手机网站开发、微商城、网站托管及成都网站维护公司、WEB系统开发、域名注册、国内外服务器租用、视频、平面设计、SEO优化排名。设计、前端、后端三个建站步骤的完善服务体系。一人跟踪测试的建站服务标准。已经为成都自拌料搅拌车行业客户提供了网站设计服务。

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.

题目大意:

判断两个二叉树是否完全相同。包括他们节点的内容。

代码如下:(递归版)

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    bool isSameTree(TreeNode* p, TreeNode* q) {
        bool childResult;
        if( NULL == p && NULL == q)
            return true;
        if( NULL != p && NULL != q && p->val == q->val)
        {
            return childResult = isSameTree(p->left,q->left) && isSameTree(p->right,q->right);
        }
        return false;
        
    }
};

2016-08-07 00:01:38


文章名称:leetCode100.SameTree树
地址分享:http://scpingwu.com/article/iecgci.html