Just like "starting from enumeration and check pattern" strategy, a good solution starts from basics.class Solution { public: void connect(TreeLinkNode *p) { if (!p) return; if (p->left) p->left->next = p->right; // with the same parent if...
Compared with I version, the tree could be incomplete. The only difference is that, we connect current node's child to next non-childrenless' node's first child. Still, we need calculate from right to left: classSolution {public:voidconnect(TreeLinkNode *p) {if(!p)return;if(p->right)...