Flatten Binary Tree to Linked Li

2019-05-04  本文已影响0人  DaiMorph

https://www.cnblogs.com/grandyang/p/4293853.html
/
5
/ \
4 6

/
4

\

\
  \
    \
      \
        \
class Solution {
public:
    void flatten(TreeNode* root) {
        if(root==NULL)return;
        if(root->left)flatten(root->left);
        if(root->right)flatten(root->right);
        TreeNode*temp=root->right;
        root->right=root->left;
        root->left=NULL;
        while(root->right)root=root->right;
        root->right=temp;
    }
};
上一篇下一篇

猜你喜欢

热点阅读