C++ || DFS
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n\n    int mod = 1e9+7;\n    vector<vector<long long>> table;\n\n    void insert(TreeNode *root, int num){\n    \n        if(root->val == -1){\n            root->val = num;\n        }\n        else{\n            if(root->val < num){\n                if(!root->right)root->right = new TreeNode(-1);\n                insert(root->right, num);\n            }\n            else{\n                if(!root->left)root->left = new TreeNode(-1);\n                insert(root->left, num);\n            }\n        }\n\n    }\n\n    pair<int, int> dp(TreeNode *root){\n        if(!root)return {0, 1};\n        else{\n\n            auto l = dp(root->left);\n            auto r = dp(root->right);\n\n            pair<int, int> p;\n            p.first = l.first + r.first + 1;\n            p.second = ((( table[p.first - 1][l.first] * l.second) % mod) * r.second) % mod;\n            \n            return p;\n        }\n    }\n\n    int numOfWays(vector<int>& nums) {\n        \n        int n = nums.size();\n        if(n>2){\n            TreeNode *root = new TreeNode(-1);\n            for(int x: nums){\n                insert(root, x);\n            }\n\n            table.resize(n + 1);\n            for(int i = 0; i < n + 1; ++i){\n                table[i] = vector<long long>(i + 1, 1);\n                for(int j = 1; j < i; ++j){\n                    table[i][j] = (table[i-1][j-1] + table[i-1][j]) % mod;\n                }\n            }\n\n            return dp(root).second - 1;\n        }\n        else return 0;\n    }\n};\n```
['Divide and Conquer', 'Dynamic Programming', 'Tree', 'Union Find', 'C++']