2ms solution with C

  • 0
    struct TreeNode *upsideDownBinaryTree(struct TreeNode *root) {
        struct TreeNode* n = root; 
        struct TreeNode* parent = NULL;
        struct TreeNode* lastRight = NULL;
            struct TreeNode* next_n = n->left;
            n->left = lastRight;
            lastRight = n->right;
            n->right = parent;
            parent = n;
            n = next_n;
        return parent;

Log in to reply

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