题目

 1 class Solution {
2 public:
3 TreeNode* mergeTrees(TreeNode* t1, TreeNode* t2) {
4 if(!t1 && !t2) return NULL;
5 if(t1 == NULL&& t2 != NULL) return t2;
6 if(t1 != NULL&& t2 == NULL) return t1;
7 TreeNode* node = new TreeNode(t1->val + t2->val);;
8 //指针赋值使用错误TreeNode* node; node->val = t1->val + t2->val;
9 node->left = mergeTrees(t1->left,t2->left);
10 node->right = mergeTrees(t1->right,t2->right);
11 return node;
12 }
13 };

需要查看C++ primer, 复习指针使用

LeetCode617. 合并二叉树的更多相关文章

  1. [Swift]LeetCode617. 合并二叉树 | Merge Two Binary Trees

    Given two binary trees and imagine that when you put one of them to cover the other, some nodes of t ...

  2. LeetCode 617. 合并二叉树(Merge Two Binary Trees)

    617. 合并二叉树 617. Merge Two Binary Trees 题目描述 给定两个二叉树,想象当你将它们中的一个覆盖到另一个上时,两个二叉树的一些节点便会重叠. 你需要将他们合并为一个新 ...

  3. Leetcode 617.合并二叉树

    合并二叉树 给定两个二叉树,想象当你将它们中的一个覆盖到另一个上时,两个二叉树的一些节点便会重叠. 你需要将他们合并为一个新的二叉树.合并的规则是如果两个节点重叠,那么将他们的值相加作为节点合并后的新 ...

  4. Java实现 LeetCode 617 合并二叉树(遍历树)

    617. 合并二叉树 给定两个二叉树,想象当你将它们中的一个覆盖到另一个上时,两个二叉树的一些节点便会重叠. 你需要将他们合并为一个新的二叉树.合并的规则是如果两个节点重叠,那么将他们的值相加作为节点 ...

  5. Leetcode617.Merge Two Binary Trees合并二叉树

    给定两个二叉树,想象当你将它们中的一个覆盖到另一个上时,两个二叉树的一些节点便会重叠. 你需要将他们合并为一个新的二叉树.合并的规则是如果两个节点重叠,那么将他们的值相加作为节点合并后的新值,否则不为 ...

  6. [LeetCode] Merge Two Binary Trees 合并二叉树

    Given two binary trees and imagine that when you put one of them to cover the other, some nodes of t ...

  7. LeetCode 617. Merge Two Binary Trees合并二叉树 (C++)

    题目: Given two binary trees and imagine that when you put one of them to cover the other, some nodes ...

  8. 【LeetCode】 617. 合并二叉树

    题目 给定两个二叉树,想象当你将它们中的一个覆盖到另一个上时,两个二叉树的一些节点便会重叠. 你需要将他们合并为一个新的二叉树.合并的规则是如果两个节点重叠,那么将他们的值相加作为节点合并后的新值,否 ...

  9. [LeetCode] 617. Merge Two Binary Trees 合并二叉树

    Given two binary trees and imagine that when you put one of them to cover the other, some nodes of t ...

随机推荐

  1. ORACLE 10g、11g批量刷新用户密码

    一.ORACLE 10g批量刷新用户密码 select 'alter user ' || username ||' identified by values '''||password ||''';' ...

  2. 移动端 better-scroll基础

    一.什么是better-scroll better-scroll 是一款重点解决移动端(已支持 PC)各种滚动场景需求的插件 #滚动原理 1. 与浏览器滚动原理一致,父容器高度固定,子元素内容撑开,必 ...

  3. [日常摸鱼]bzoj1007[HNOI2008]水平可见直线-半平面交(对偶转凸包)

    不会写半平面交-然后发现可以转成对偶凸包问题 具体见这里:http://trinkle.blog.uoj.ac/blog/235 相关的原理我好像还是不太懂-orz #include<cstdi ...

  4. pytest接口测试轻松入门

    通过Postman请求结果如下图: 那我们怎么用pytest进行测试呢? 在接口测试,我们要用到requests包,实现代码如下: import pytest import allure import ...

  5. Leetcode 220 周赛 题解

    5629. 重新格式化电话号码 模拟 注意一些细节,最后位置是否取值. class Solution { public: string reformatNumber(string number) { ...

  6. 模拟sql注入实现远程桌面登录

    首先用sql注入文件命令y url+一句话 into outfile 绝对路径/test.php 用蚁剑连接打开连接的终端 先看用户的权限 创建一个用户将它放入队列中 查看3389端口是否开启 0xd ...

  7. 用burp爆破tomcat的过程

    首先burp抓包,将抓到的包放到intruder中 通过burp中自带的解码得知账号密码中有个":"号 所以我们选择的数据类型为Custom iterator 第二条输入" ...

  8. Webpack的学习总结(1)

    入门 Webpack,看这篇就够了 入门 Webpack,看这篇就够了 写在前面的话 一个基础的webpack配置文件 什么是WebPack,为什么要使用它? WebPack和Grunt以及Gulp相 ...

  9. #2020征文-手机#深鸿会深大小组:HarmonyOS手机游戏—数字华容道

    目录: 前言 概述 正文 创建项目 实现初始界面布局 实现数字的随机打乱 实现滑动或点击调换数字 实现游戏成功界面 结语 源码包 前言 12月16号HarmonyOS2.0手机开发者Beta版已经发布 ...

  10. ASP.NET Web API运行提示:找到了与该请求匹配的多个操作的解决方法