Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Definition for a binary tree node.
- * struct TreeNode {
- * int val;
- * TreeNode *left;
- * TreeNode *right;
- * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
- * };
- */
- class Solution {
- TreeNode* construct(vector<int> nums,int start, int end)
- {
- if(start>end)
- return NULL;
- int i,index,v = INT_MIN;
- for(i=start;i<=end;i++)
- if(nums[i]>v)
- {
- v = nums[i];
- index = i;
- }
- }
- TreeNode* root = new TreeNode(v);
- root->left = construct(nums,start,index-1);
- root->right = construct(nums,index+1,end);
- return root;
- }
- public:
- TreeNode* constructMaximumBinaryTree(vector<int>& nums) {
- return construct(nums,0,nums.size()-1);
- }
- };
- Line 27: 'root' does not name a type
Add Comment
Please, Sign In to add comment