2ms solution with C


  • 0
    H
    struct TreeNode *upsideDownBinaryTree(struct TreeNode *root) {
        struct TreeNode* n = root; 
        struct TreeNode* parent = NULL;
        struct TreeNode* lastRight = NULL;
        while(n){
            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.