What is wrong of this line "TreeNode *pop_tree = new TreeNode;" ?


  • 0
    B

    In my code, I have this line:

    TreeNode *pop_tree = new TreeNode;

    Then I got an error after I submitted:

    Line 41: no matching function for call to 'TreeNode::TreeNode()'

    Why?

    Thanks.


  • 0
    S

    Take a look at this comment in code definition

    /**
     * Definition for binary tree
     * struct TreeNode {
     *     int val;
     *     TreeNode *left;
     *     TreeNode *right;
     *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
     * };
     */
    

    It should be TreeNode *pop_tree = new TreeNode(x); to create a new node.


  • 0
    B

    Got it. Thanks very much.


  • 0
    B

    Got it. Thanks very much.


Log in to reply
 

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