My code gets Runtime Error on submission, while it's ok in playground


  • 0
    X
    class Solution {
    public:
        TreeNode* trimBST(TreeNode* root, int L, int R) {
            if (!root) return nullptr;
            if (root->val >= L && root->val <= R) {
                root->left = trimBST(root->left, L, R);
                root->right = trimBST(root->right, L, R);
                return root;
            }
            TreeNode *del_root = root;
            if (root->val < L) root = trimBST(root->right, L, R);
            else               root = trimBST(root->left, L, R);
            delete del_root;
            return root;
        }
    };
    

    Submission Details:
    Input:
    [1,null,2]
    2
    4
    Error:member access within misaligned address 0x000000000021 for type 'struct TreeNode', which requires 8 byte alignment

    In playground:
    Finished in 0 ms
    [2, null, null]

    Why?


Log in to reply
 

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