I got Compile Error but code works good in VS2010. Anyone can help?


  • 0
    P

    Leetcode gives me a compile error

    required from 'std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with _InputIterator = int; _Tp = TreeNode*; _Alloc = std::allocator<TreeNode*>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<TreeNode*>]'
    

    But the code works fine in VS2010. Any one has ideas what's wrong with my code?

    TreeNode *copyTree(TreeNode* root, int base){
    	if(!root){
    		return NULL;
    	}
    
    	TreeNode *newRoot = new TreeNode(root->val + base);
    	newRoot->left = copyTree(root->left, base);
    	newRoot->right = copyTree(root->right, base);
    	return newRoot;
    }
    
    vector<TreeNode *> generateTrees(int n) {
    	vector<vector<TreeNode *>> dp;
    	vector<TreeNode *> zero(1, NULL);
    	vector<TreeNode *> one(1, new TreeNode(1));
    	dp.push_back(zero);
    	dp.push_back(one);
    
    	for(int i = 2; i <= n; i++){
    		vector<TreeNode *> temp;
    		for(int mid = 1; mid <= i; mid++){
    			int left = mid - 1;
    			int right = i - mid;
    			for(int ll = 0; ll < dp[left].size(); ll++){
    				for(int rr = 0; rr < dp[right].size(); rr++){
    					TreeNode *r = new TreeNode(mid);
    					r->left = copyTree(dp[left][ll], 0);
    					r->right = copyTree(dp[right][rr], mid);
    					temp.push_back(r);
    				}
    			}
    		}
    		dp.push_back(temp);
    	}
    
    	return dp[n];
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.