226. 翻转二叉树-leetcode

<?xml version="1.0" encoding="utf-8"?> 226. 翻转二叉树-leetcode <style type="text/css"> </style> <body>

226. 翻转二叉树-leetcode

Table of Contents

1 题目

226. 翻转二叉树

2 代码

/**
 * Definition for a binary tree node.
 * class TreeNode {
 *     public $val = null;
 *     public $left = null;
 *     public $right = null;
 *     function __construct($value) { $this->val = $value; }
 * }
 */
class Solution {

    /**
     * @param TreeNode $root
     * @return TreeNode
     */
    function invertTree($root) {
    if (empty($root)) {
        return $root;
    }

    $tmp = $root->left;
    $root->left = $root->right;
    $root->right = $tmp;

    $this->invertTree($root->left);
    $this->invertTree($root->right);
    return $root;
    }
}

Author: 吴丹阳

Created: 2020-08-28 Fri 13:29

Validate

上一篇:LeetCode第226场周赛


下一篇:CSS绘图和数据存储原理