Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- private:
- int simple(TreeLinkNode *root)
- {
- if (root->left == NULL)
- return 1;
- simple(root->left);
- int d = simple(root->right) + 1;
- if (d > 1)
- {
- TreeLinkNode *l = root->left, *r = root->right;
- for(int i = d - 1; i; --i)
- {
- l->next = r;
- l = l->right;
- r = r->left;
- }
- }
- return d;
- }
- public:
- void connect(TreeLinkNode *root) {
- if (root == NULL)
- return;
- simple(root);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement