Advertisement
tanchukw

Untitled

Nov 4th, 2015
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. class Solution {
  2. private:
  3.     int simple(TreeLinkNode *root)
  4.     {
  5.         if (root->left == NULL)
  6.             return 1;
  7.         simple(root->left);
  8.         int d = simple(root->right) + 1;
  9.         if (d > 1)
  10.         {
  11.             TreeLinkNode *l = root->left, *r = root->right;
  12.             for(int i = d - 1; i; --i)
  13.             {
  14.                 l->next = r;
  15.                 l = l->right;
  16.                 r = r->left;
  17.             }
  18.         }
  19.         return d;
  20.     }
  21. public:
  22.     void connect(TreeLinkNode *root) {
  23.         if (root == NULL)
  24.             return;
  25.         simple(root);
  26.     }
  27. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement