mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
32 lines
926 B
HTML
32 lines
926 B
HTML
<p>Given the <code>root</code> of a binary tree, invert the tree, and return <em>its root</em>.</p>
|
|
|
|
<p> </p>
|
|
<p><strong>Example 1:</strong></p>
|
|
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/14/invert1-tree.jpg" style="width: 500px; height: 165px;" />
|
|
<pre>
|
|
<strong>Input:</strong> root = [4,2,7,1,3,6,9]
|
|
<strong>Output:</strong> [4,7,2,9,6,3,1]
|
|
</pre>
|
|
|
|
<p><strong>Example 2:</strong></p>
|
|
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/14/invert2-tree.jpg" style="width: 500px; height: 120px;" />
|
|
<pre>
|
|
<strong>Input:</strong> root = [2,1,3]
|
|
<strong>Output:</strong> [2,3,1]
|
|
</pre>
|
|
|
|
<p><strong>Example 3:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> root = []
|
|
<strong>Output:</strong> []
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li>The number of nodes in the tree is in the range <code>[0, 100]</code>.</li>
|
|
<li><code>-100 <= Node.val <= 100</code></li>
|
|
</ul>
|