diff --git a/problems/0106.从中序与后序遍历序列构造二叉树.md b/problems/0106.从中序与后序遍历序列构造二叉树.md index 0144fc5c..dc517480 100644 --- a/problems/0106.从中序与后序遍历序列构造二叉树.md +++ b/problems/0106.从中序与后序遍历序列构造二叉树.md @@ -1228,6 +1228,19 @@ impl Solution { } } ``` +### C# +```C# +public TreeNode BuildTree(int[] inorder, int[] postorder) +{ + if (inorder.Length == 0 || postorder.Length == null) return null; + int rootValue = postorder.Last(); + TreeNode root = new TreeNode(rootValue); + int delimiterIndex = Array.IndexOf(inorder, rootValue); + root.left = BuildTree(inorder.Take(delimiterIndex).ToArray(), postorder.Take(delimiterIndex).ToArray()); + root.right = BuildTree(inorder.Skip(delimiterIndex + 1).ToArray(), postorder.Skip(delimiterIndex).Take(inorder.Length - delimiterIndex - 1).ToArray()); + return root; +} +```