标签:item ati leetcode flatten tree https text etc while
给定一个二叉树,原地将它展开为链表。
例如,给定二叉树
1
/ \
2 5
/ \ \
3 4 6
将其展开为:
1
\
2
\
3
\
4
\
5
\
6
1 class Solution{ 2 public: 3 void flatten(TreeNode* root){ 4 if (root == NULL) return; 5 flatten(root->left); 6 flatten(root->right); 7 TreeNode *temp = root->right; 8 root->right = root->left; 9 root->left = NULL; 10 while (root->right) root = root->right; 11 root->right = temp; 12 } 13 }
标签:item ati leetcode flatten tree https text etc while
原文地址:https://www.cnblogs.com/kexinxin/p/10163099.html