📌 C++ || Beats - 97% || Explained Using Level Order Traversal
Best Solution for Beginners\nWe can solve this using Level order Traversal.\n\n    Runtime - 97.14%\uD83D\uDD25 \n\n# Approach\n1. Firstly We will do Level Orde
# Best Solution for Beginners\nWe can solve this using Level order Traversal.\n\n    Runtime - 97.14%\uD83D\uDD25 \n\n# Approach\n1. Firstly We will do Level Order Travesal.\n2. Then at Each Level we will join all nodes present at that Level.\n\n#  If you like the solution and understand it then Please Upvote.\u2B06\uFE0F\u2764\uFE0F \n\t* PEACE OUT LUV\u270C\uFE0F*\n\n# Code\n```\n/*\nclass Solution {\npublic:\n    Node* connect(Node* root) {\n        if(root == NULL){\n            return root;\n        }\n        queue<Node*>q;\n        q.push(root);\n        while(!q.empty()){\n            int size = q.size();\n            vector<Node*>ans;\n            for(int i=0; i<size; i++){\n                Node* node = q.front();\n                q.pop();\n                if(node ->left)q.push(node ->left);\n                if(node ->right)q.push(node ->right);\n                ans.push_back(node);\n            }\n            for(int i=1; i<ans.size(); i++){\n                ans[i-1] ->next = ans[i];\n            }\n        }\n        return root;\n    }\n};\n```
['Linked List', 'Tree', 'Breadth-First Search', 'C++']