C# | Recursion
Code\n\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     public int val;\n *     public TreeNode left;\n *     public TreeNode rig
# Code\n```\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     public int val;\n *     public TreeNode left;\n *     public TreeNode right;\n *     public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {\n *         this.val = val;\n *         this.left = left;\n *         this.right = right;\n *     }\n * }\n */\npublic class Solution {\n    public TreeNode BuildTree(int[] inorder, int[] postorder) \n    {\n        TreeNode? Build(Span<int> inorder, Span<int> postorder)\n        {\n            if (postorder.IsEmpty || inorder.IsEmpty)\n            {\n                return null;\n            }\n\n            var pos = inorder.IndexOf(postorder[^1]);\n            return new TreeNode(postorder[^1])\n            {\n                left = Build(inorder[..pos], postorder[..pos]),\n                right = Build(inorder[(pos + 1)..], postorder[pos..^1])\n            };\n        }\n\n        return Build(inorder, postorder);\n    }\n}\n```
['C#']