fork download
  1. /**
  2.  * Definition for binary tree
  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. public:
  12. int i;
  13. vector<int> V;
  14. TreeNode *make(int start,int end)
  15. {
  16. if(start>end) return NULL;
  17. int mid= start + (end-start)/2;
  18. TreeNode *t=(TreeNode *)malloc(sizeof(TreeNode));
  19. t->left=make(start,mid-1);
  20. t->val=V[i++];
  21. t->right=make(mid+1,end);
  22. return t;
  23. }
  24. TreeNode *sortedArrayToBST(vector<int> &num) {
  25. // Start typing your C/C++ solution below
  26. // DO NOT write int main() function
  27. i=0;
  28. V=num;
  29. int n=num.size();
  30. return make(0,n-1);
  31. }
  32. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:13:5: error: ‘vector’ does not name a type
prog.cpp:14:5: error: ‘TreeNode’ does not name a type
prog.cpp:24:5: error: ‘TreeNode’ does not name a type
stdout
Standard output is empty