✔️ 100% Fastest Swift Solution
\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     public var val: Int\n *     public var left: TreeNode?\n *     public var right
```\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     public var val: Int\n *     public var left: TreeNode?\n *     public var right: TreeNode?\n *     public init() { self.val = 0; self.left = nil; self.right = nil; }\n *     public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }\n *     public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {\n *         self.val = val\n *         self.left = left\n *         self.right = right\n *     }\n * }\n */\nclass Solution {\n    func buildTree(_ inorder: [Int], _ postorder: [Int]) -> TreeNode? {\n        guard postorder.count > 0 else { return nil }\n        \n        let totalCount = postorder.count\n        let root = TreeNode(postorder[totalCount - 1])\n        var rootIndex = -1\n        \n        for (i, val) in inorder.enumerated() {\n            if val == root.val {\n                rootIndex = i\n                break\n            } \n        }\n        \n        let leftCount = rootIndex\n        let rightCount = totalCount - leftCount - 1\n        \n        root.left = buildTree(Array(inorder[0..<leftCount]), Array(postorder[0..<leftCount]))\n        root.right = buildTree(Array(inorder[1 + leftCount..<totalCount]), Array(postorder[leftCount..<totalCount - 1]))\n        return root\n    }\n    \n}\n```\n\nLet me know in comments if you have any doubts. I will be happy to answer.\n\nPlease upvote if you found the solution useful.
['Swift']