剑指offer-二叉树的镜像-php
来源:互联网 发布:数据库管理系统有哪些 编辑:程序博客网 时间:2024/06/01 18:46
题目
操作给定的二叉树,将其变换为源二叉树的镜像。
题解
翻转二叉树,有递归和非递归两种方式,非递归就是使用队列。
代码
<?php/*class TreeNode{ var $val; var $left = NULL; var $right = NULL; function __construct($val){ $this->val = $val; }}*/function Mirror(&$root){ if($root == NULL) return 0; $queue = array(); array_push($queue, $root); while(!empty($queue)){ $node = array_shift($queue); $tmp = $node->left; $node->left = $node->right; $node->right = $tmp; if($node->left != NULL) array_push($queue, $node->left); if($node->right != NULL) array_push($queue, $node->right); }}
0 0
- 剑指offer-二叉树的镜像-php
- 【剑指offer】二叉树的镜像
- [剑指Offer]二叉树的镜像
- 剑指offer--二叉树的镜像
- 剑指Offer-二叉树的镜像
- 《剑指offer》二叉树的镜像
- 剑指 offer:二叉树的镜像
- 【剑指offer】二叉树的镜像
- 剑指offer 二叉树的镜像
- [剑指offer]二叉树的镜像
- 《剑指offer》-二叉树的镜像
- 剑指Offer:二叉树的镜像
- 剑指offer|二叉树的镜像
- 《剑指offer》二叉树的镜像
- 剑指Offer:二叉树的镜像
- 【剑指offer】二叉树的镜像
- 剑指Offer:二叉树的镜像
- 剑指offer-二叉树的镜像
- 算法-1-堆和队列-汇总(持续更新)-目录呈现
- L2-005. 集合相似度(set集合)
- Webstorm 创建文件使用模板自动生成代码
- Linux 编译 OpenCV 出现 ‘cv::imread(std::__cxx11:: 错误的解决方案
- 【ORACLE】逗号分隔的字符串的应用
- 剑指offer-二叉树的镜像-php
- c#上Redis示例<一.写>
- c++上机实验3 个人所得税计算器
- Codeforces Round #304 (Div. 2) C. Soldier and Cards —— 模拟题,队列
- 填了支付宝支付的一个大坑
- 多个tomcat同时运行端口修改
- golang 实现一个restful微服务
- 笔记3.24
- java连接docker中的oracle问题解决方案