👏🏻 Python - DFS 公瑾™
96. Unique Binary Search Trees\n\n> \u7C7B\u578B\uFF1A\n> Time Complexity O(N)\n> Space Complexity O(N)\n\n\n\u8FD9\u9898\u5F88\u5DE7\u5999\u7684\u8FD0\u7528\u4
### 96. Unique Binary Search Trees\n```\n> \u7C7B\u578B\uFF1A\n> Time Complexity O(N)\n> Space Complexity O(N)\n```\n\n\u8FD9\u9898\u5F88\u5DE7\u5999\u7684\u8FD0\u7528\u4E86Binary Search\u7684\u4E00\u4E9B\u6027\u8D28\uFF0C\u7136\u540E\u914D\u5408Binary Search Tree\u7684\u7279\u5F81\u3002\n\u6BCF\u6B21\u627E\u5BFB\u4E2D\u95F4\u70B9\uFF0C\u7136\u540E\u5DE6\u53F3\u5206\u914D\u3002\n\u4F18\u5316\u90E8\u5206\u89E3\u51B3\u4E86\u6BCF\u6B21Slicing\u591A\u4ED8\u51FA\u7684\u65F6\u95F4\u590D\u6742\u5EA6\u3002\n\n\n#### DFS\n```python\nclass Solution(object):\n    def sortedArrayToBST(self, nums):\n        if not nums: return None\n        l, r = 0, len(nums) - 1\n        mid = (l + (r - l)) // 2\n        node = TreeNode(nums[mid])\n        node.left = self.sortedArrayToBST(nums[:mid])\n        node.right = self.sortedArrayToBST(nums[mid+1:])\n        return node\n```\n\n#### DFS\u4F18\u5316\n\n```python     \nclass Solution(object):\n    def sortedArrayToBST(self, nums):\n        self.nums = nums\n        return self.dfs(0, len(nums) - 1)\n    \n    def dfs(self, l, r):\n        if l > r: return None\n        mid = (l + r) // 2\n        node = TreeNode(self.nums[mid])\n        node.left = self.dfs(l, mid - 1)\n        node.right = self.dfs(mid + 1, r)\n        return node\n```
[]