✅ Simple Swift [O(n) Time, O(n) Space]
Code\n\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
# Code\n```\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 sortedArrayToBST(_ nums: [Int]) -> TreeNode? {\n        guard nums.count > 0 else { return nil }\n        let mid = nums.count / 2\n        var newNode = TreeNode(nums[mid])\n        newNode.left = sortedArrayToBST(Array(nums[0..<mid]))\n        newNode.right = sortedArrayToBST(Array(nums[mid+1..<nums.count]))\n        return newNode\n    }\n}\n```
['Swift']