Skip to content

Commit 020ec1a

Browse files
authored
Merge pull request #3654 from NotADucc/0144
create 0144-binary-tree-preorder-traversal.cs
2 parents 4dc3857 + f527ce6 commit 020ec1a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Diff for: csharp/0144-binary-tree-preorder-traversal.cs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class Solution {
2+
public IList<int> PreorderTraversal(TreeNode root)
3+
{
4+
var output = new List<int>();
5+
Traverse(output, root);
6+
return output;
7+
}
8+
9+
private void Traverse(List<int> output, TreeNode root)
10+
{
11+
if (root is null)
12+
{
13+
return;
14+
}
15+
16+
output.Add(root.val);
17+
Traverse(output, root.left);
18+
Traverse(output, root.right);
19+
}
20+
}

0 commit comments

Comments
 (0)