Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 734616d

Browse files
committed
Update 0106.添加C#版
1 parent 0d99307 commit 734616d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

‎problems/0106.从中序与后序遍历序列构造二叉树.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,19 @@ impl Solution {
12281228
}
12291229
}
12301230
```
1231+
### C#
1232+
```C#
1233+
public TreeNode BuildTree(int[] inorder, int[] postorder)
1234+
{
1235+
if (inorder.Length == 0 || postorder.Length == null) return null;
1236+
int rootValue = postorder.Last();
1237+
TreeNode root = new TreeNode(rootValue);
1238+
int delimiterIndex = Array.IndexOf(inorder, rootValue);
1239+
root.left = BuildTree(inorder.Take(delimiterIndex).ToArray(), postorder.Take(delimiterIndex).ToArray());
1240+
root.right = BuildTree(inorder.Skip(delimiterIndex + 1).ToArray(), postorder.Skip(delimiterIndex).Take(inorder.Length - delimiterIndex - 1).ToArray());
1241+
return root;
1242+
}
1243+
```
12311244

12321245
<p align="center">
12331246
<a href="https://programmercarl.com/other/kstar.html" target="_blank">

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /