剑指offer-二叉树的镜像
来源:互联网 发布:淘宝号交易 编辑:程序博客网 时间:2024/06/08 21:49
操作给定的二叉树,将其变换为源二叉树的镜像。
解题思路:对于根节点的左右子树,无须再单独考虑是否为空,全部交换。依次递归。
/*struct TreeNode {int val;struct TreeNode *left;struct TreeNode *right;TreeNode(int x) :val(x), left(NULL), right(NULL) {}};*/class Solution {public: void Mirror(TreeNode *pRoot) { if(pRoot==NULL) return; TreeNode *temp=pRoot->left; pRoot->left=pRoot->right; pRoot->right=temp; Mirror(pRoot->left); Mirror(pRoot->right); }};
0 0
- 【剑指offer】二叉树的镜像
- [剑指Offer]二叉树的镜像
- 剑指offer--二叉树的镜像
- 剑指Offer-二叉树的镜像
- 《剑指offer》二叉树的镜像
- 剑指 offer:二叉树的镜像
- 【剑指offer】二叉树的镜像
- 剑指offer 二叉树的镜像
- [剑指offer]二叉树的镜像
- 《剑指offer》-二叉树的镜像
- 剑指Offer:二叉树的镜像
- 剑指offer|二叉树的镜像
- 《剑指offer》二叉树的镜像
- 剑指Offer:二叉树的镜像
- 【剑指offer】二叉树的镜像
- 剑指Offer:二叉树的镜像
- 剑指offer-二叉树的镜像
- 剑指offer 二叉树的镜像
- Android学习笔记---体系与系统架构(20170426)
- 基于proteus的51单片机仿真实例三、新建一个keil c51工程
- python调用c的记录
- leetcode-3sum closest
- 多叉树的深度遍历
- 剑指offer-二叉树的镜像
- 软件开发的心得体会(一)
- CentOS 调整时间
- 常见字符串类
- ## 递归与尾递归 ##
- POJ 1396 All in All
- 【Java Utility】Jsoup网页爬虫工具--从元素/元素集中提取属性、文本和HTML内容【九】
- SKlearn库EM算法混合高斯模型参数说明及代码实现
- 【51Nod】1012 最小公倍数LCM