void flatten(TreeNode* root) {
if(!root) return ;
TreeNode* cur = root;
TreeNode* pre = NULL;
while(cur){
if(cur -> left){
pre = cur -> left;
while(pre -> right)
pre = pre -> right;
pre -> right = cur -> right;
cur -> right = cur -> left;
cur -> left = NULL;
}
cur = cur -> right;
}
}
解释:
捕获.PNG
网友评论