mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
Update 0106.添加C#版
This commit is contained in:
@ -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;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||||
|
Reference in New Issue
Block a user