mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-13 14:57:08 +00:00
32 lines
1.1 KiB
Markdown
32 lines
1.1 KiB
Markdown
<h2><a href="https://leetcode.com/problems/binary-tree-preorder-traversal/">144. Binary Tree Preorder Traversal</a></h2><h3>Easy</h3><hr><div><p>Given the <code>root</code> of a binary tree, return <em>the preorder traversal of its nodes' values</em>.</p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
<img alt="" src="https://assets.leetcode.com/uploads/2020/09/15/inorder_1.jpg" style="width: 125px; height: 200px;">
|
|
<pre><strong>Input:</strong> root = [1,null,2,3]
|
|
<strong>Output:</strong> [1,2,3]
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<pre><strong>Input:</strong> root = []
|
|
<strong>Output:</strong> []
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 3:</strong></p>
|
|
|
|
<pre><strong>Input:</strong> root = [1]
|
|
<strong>Output:</strong> [1]
|
|
</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>
|
|
|
|
<p> </p>
|
|
<p><strong>Follow up:</strong> Recursive solution is trivial, could you do it iteratively?</p>
|
|
</div> |