leetcode114
程序代码:
struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {} }; class Solution { public: void flatten(TreeNode* root) {//后序遍历; if(root==NULL)return; flatten(root->left); flatten(root->right); TreeNode *temp=root->right; root->right=root->left; root->left=NULL; while(root->right)root=root->right; root->right=temp; } };
while那行改变了root,root不就不是头结点了吗,这么做为什么没有问题?