✅✅|| Recursion || C++ || Clean & Simple Code || Explanation ||✅✅
\n# Method 1\n\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeN
\n# Method 1\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\n class Solution {\n public:\n     TreeNode* sortedArrayToBST(vector<int>& nums) {\n         // We have to create a hight balanced BST\n         // elements are strictly increasing\n         if(nums.size()==0)return NULL;\n         if(nums.size()==1) return new TreeNode(nums[0]);\n         int middle = nums.size()/2;\n         TreeNode* root = new TreeNode(nums[middle]);\n         vector<int> leftsub(nums.begin(), nums.begin()+middle);\n         vector<int> rightsub(nums.begin()+ middle+1, nums.end());\n         root->left = sortedArrayToBST(leftsub);\n         root->right = sortedArrayToBST(rightsub);\n         return root;\n     }\n };\n```\n\n# METHOD 2\n```\nclass Solution {\npublic:\n    TreeNode* sortedArrayToBST(vector<int>& nums) {\n        // Base condition...\n        if (nums.size() == 0)\n\t\t\treturn NULL;\n        // Call the function recursively...\n\t\treturn sortedArrayToBST(nums, 0, nums.size() - 1);\n    }\n    // Create another function which will convert any particular range of given nums array...\n    // & return its corresponding BST root node....\n\tTreeNode* sortedArrayToBST(vector<int>& nums, int beg, int end) {\n        // If beg > end, return NULL, as we receive a wrong range...\n\t\tif (beg > end)\n\t\t\treturn NULL;\n        // If beg == end, return a new node having value same as nums[beg]... \n        if(beg == end)\n            return new TreeNode(nums[beg]);\n        // set the middle node...\n\t\tint mid = (beg + end) / 2;\n        // Initialise root node with value same as nums[mid]\n\t\tTreeNode* root = new TreeNode(nums[mid]);\n        // Assign left subtrees as the same function called on left subranges...\n\t\troot->left = sortedArrayToBST(nums, beg, mid - 1);\n        // Assign right subtrees as the same function called on right subranges...\n\t\troot->right = sortedArrayToBST(nums, mid + 1, end);\n        // Return the root node\n\t\treturn root;\n    }\n};\n```
['Array', 'Divide and Conquer', 'Tree', 'Binary Search Tree', 'C++']