剑指offer 二叉树的镜像
来源:互联网 发布:如果当时 知乎 编辑:程序博客网 时间:2024/06/05 18:28
最近在刷剑指offer的题目,刚好碰到树,我比较薄弱的一环,将自己思路写出来和大家一起分享
时间限制:1秒 空间限制:32768K 热度指数:98039
题目描述
操作给定的二叉树,将其变换为源二叉树的镜像。
输入描述:
二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树 8 / \ 10 6 / \ / \ 11 9 7 5
直接附上AC代码:
/*
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;
swap(pRoot->left,pRoot->right);
Mirror(pRoot->left);
Mirror(pRoot->right);
}
};
阅读全文
1 0
- 【剑指offer】二叉树的镜像
- [剑指Offer]二叉树的镜像
- 剑指offer--二叉树的镜像
- 剑指Offer-二叉树的镜像
- 《剑指offer》二叉树的镜像
- 剑指 offer:二叉树的镜像
- 【剑指offer】二叉树的镜像
- 剑指offer 二叉树的镜像
- [剑指offer]二叉树的镜像
- 《剑指offer》-二叉树的镜像
- 剑指Offer:二叉树的镜像
- 剑指offer|二叉树的镜像
- 《剑指offer》二叉树的镜像
- 剑指Offer:二叉树的镜像
- 【剑指offer】二叉树的镜像
- 剑指Offer:二叉树的镜像
- 剑指offer-二叉树的镜像
- 剑指offer 二叉树的镜像
- 《c primer plus》笔记<一>
- github上传本地项目指南
- c#开发大全、系列文章、精品教程
- MySQL 索引
- c#读取图片成rgb二维数组
- 剑指offer 二叉树的镜像
- CSS是什么及其继承与选择器
- 工程师开发流程规范
- 循环队列--击鼓传花或者叫烫手的山芋(hot potato)
- memcached
- 使用LAYUI父页面向子页面传参
- 接上一个webpack资源整合。我觉得这样更清晰
- 1100. Mars Numbers (20)
- 深度框架概述