1class Solution {2public:3// constant space4// we only need start node of each level if we have already populated the next5// right pointers in that level6// node->left->next = node->right7// if node->next != NULL , node->right->next = node->next=>left89Node *connect(Node *root) {10Node *temp = root;11while (temp != NULL) {12Node *start = temp;13temp = start->left;14if (temp != NULL) {15while (start != NULL) {16start->left->next = start->right;17if (start->next != NULL) {18start->right->next = start->next->left;19}20start = start->next;21}22}23}24return root;25}26};