1 Star 0 Fork 1

hesuyang/php-leetcode

forked from shyiran/php-leetcode 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
leetcode-0226-invertTree.php 570 Bytes
一键复制 编辑 原始数据 按行查看 历史
shyiran 提交于 2022-12-14 17:04 +08:00 . 补充
<?php
/**
* @Time: 2020/9/16
* @DESC: 226. 翻转二叉树
* 翻转一棵二叉树。
* 示例:
输入:
4
/ \
2 7
/ \ / \
1 3 6 9
输出:
4
/ \
7 2
/ \ / \
9 6 3 1
* @param $root
* @return null
* @link: https://leetcode-cn.com/problems/invert-binary-tree/
*/
function invertTree($root) {
if ($root == null) return null;
$left = invertTree($root->left);
$right = invertTree($root->right);
$root->left = $right;
$root->right = $left;
return $root;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/hesuyang/php-leetcode.git
git@gitee.com:hesuyang/php-leetcode.git
hesuyang
php-leetcode
php-leetcode
master

搜索帮助