Python short and clean.
Approach\nTL;DR, Similar to Editorial solution.\n\n# Complexity\n- Time complexity: O(n ^ 2)\n\n- Space complexity: O(n ^ 2)\n\n# Code\npython\nclass Solution:\
# Approach\nTL;DR, Similar to [Editorial solution](https://leetcode.com/problems/number-of-ways-to-reorder-array-to-get-same-bst/editorial/).\n\n# Complexity\n- Time complexity: $$O(n ^ 2)$$\n\n- Space complexity: $$O(n ^ 2)$$\n\n# Code\n```python\nclass Solution:\n    def numOfWays(self, nums: list[int]) -> int:\n        M = 1_000_000_007\n\n        def num_ways(bst: Sequence[int]) -> int:\n            if len(bst) <= 2: return 1\n            lefts, rights = [x for x in bst if x < bst[0]], [x for x in bst if x > bst[0]]\n            return num_ways(lefts) * num_ways(rights) * comb(len(lefts) + len(rights), len(lefts)) % M\n        \n        return (num_ways(nums) - 1) % M\n\n\n```
['Divide and Conquer', 'Binary Search Tree', 'Combinatorics', 'Python', 'Python3']