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...
Still, we need calculate from right to left: classSolution {public:voidconnect(TreeLinkNode *p) {if(!p)return;if(p->right) { p->right->next =NULL;if(p->next) { TreeLinkNode*pTmp = p->next;while(pTmp) {if(pTmp->left || pTmp->right)break; pTmp= pTmp->next; }if(pTmp) {if...