What's the difference between the two ways of creating a structure?
No.1 is right, and No.2 gives the error:
reference binding to misaligned address 0x63775f5f00676e6f for type 'const int', which requires 4 byte alignment
What's the difference between the two ways of creating a structure?
What did the No.2 do?
Here is my codes.
Thank you.
/**
 * 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 {
public:
    TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) {     
        if (preorder.size() == 0 || inorder.size() == 0)
            return nullptr;
        // # 1
        // struct TreeNode *RootTree = new TreeNode(preorder.front());
        // # 2
        struct TreeNode RootNode(preorder.front());
        struct TreeNode *RootTree = &RootNode;
        return RootTree;
    }    
};
 
    