Guest User

Untitled

a guest
Jan 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. /**
  2. * Definition for a binary tree node.
  3. * struct TreeNode {
  4. * int val;
  5. * TreeNode *left;
  6. * TreeNode *right;
  7. * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
  8. * };
  9. */
  10. class Solution {
  11. TreeNode* construct(vector<int> nums,int start, int end)
  12. {
  13. if(start>end)
  14. return NULL;
  15.  
  16. int i,index,v = INT_MIN;
  17. for(i=start;i<=end;i++)
  18.  
  19. if(nums[i]>v)
  20. {
  21. v = nums[i];
  22. index = i;
  23. }
  24. }
  25.  
  26. TreeNode* root = new TreeNode(v);
  27. root->left = construct(nums,start,index-1);
  28. root->right = construct(nums,index+1,end);
  29. return root;
  30. }
  31. public:
  32. TreeNode* constructMaximumBinaryTree(vector<int>& nums) {
  33. return construct(nums,0,nums.size()-1);
  34. }
  35. };
  36.  
  37. Line 27: 'root' does not name a type
Add Comment
Please, Sign In to add comment