leetcode-第十八周
来源:互联网 发布:闪字软件下载 编辑:程序博客网 时间:2024/05/20 21:57
617. Merge Two Binary Trees
/** * 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 {private: void helper(TreeNode *t1, TreeNode *t2, TreeNode **root) { if (!t1 && !t2) return; int lhs = t1? t1->val: 0, rhs = t2? t2->val: 0; *root = new TreeNode(lhs + rhs); TreeNode *t1left = nullptr, *t1right = nullptr; if (t1) t1left = t1->left, t1right = t1->right; TreeNode *t2left = nullptr, *t2right = nullptr; if (t2) t2left = t2->left, t2right = t2->right; helper( t1left , t2left , &((*root)->left ) ); helper( t1right, t2right, &((*root)->right) ); }public: TreeNode* mergeTrees(TreeNode* t1, TreeNode* t2) { TreeNode *ret = nullptr; TreeNode **root = &ret; helper(t1, t2, root); return ret; }};
阅读全文
0 0
- leetcode-第十八周
- 第十八周leetcode题
- leetcode第十八周解题总结-贪心算法
- 第十八周
- 第十八周
- 第十八周:[leetCode] 74. Search a 2D Matrix
- 第十八周:[Leetcode]74. Search a 2D Matrix
- 第十八周:[Leetcode]240. Search a 2D Matrix II
- 第十八周:[Leetcode]104. Maximum Depth of Binary Tree
- 第十八周:[Leetcode]111. Minimum Depth of Binary Tree
- 第十八周:[Leetcode]98. Validate Binary Search Tree
- 第十八周总结
- 第十八周作业 1.0
- 第十八周工作总结
- 第十八周工作日志
- 第十八周 动态规划
- 第十八
- leetcode【第十八周】以特定次数替换字符并计算最长重复字符串
- Redis的应用场景
- vxWorks系统ps2键盘,tty设备,vga设备的联系
- PHP -微信token验证,单图文,多图文等一般操作
- 小结
- matlab 二维空间变换-maketform imtransform 用法
- leetcode-第十八周
- ROS教程(十九):手动创建ROS package
- Linux下卸载和安装JDK
- kindle读书笔记——2017.05.22-06.21
- 学习LINUX之常用命令整理
- angularJs-工具方法!
- javascript标签
- Python廖雪峰实战web开发(Day14-完成Web App)
- RFID、LoRa和NB-IoT相关总结