【leetcode】114. 二叉树展开为链表

 

void flatten(struct TreeNode* root) {
    struct TreeNode* curr = root;
    while (curr != NULL) {
        if (curr->left != NULL) {
            struct TreeNode* next = curr->left;
            struct TreeNode* predecessor = next;
            while (predecessor->right != NULL) {
                predecessor = predecessor->right;
            }
            predecessor->right = curr->right;
            curr->left = NULL;
            curr->right = next;
        }
        curr = curr->right;
    }
}

 

posted @ 2020-12-18 11:18  温暖了寂寞  阅读(33)  评论(0编辑  收藏  举报