C++ Easiest BFS.DFS explained solution 4ms beats 91%
BFS Solution\n\nclass Solution {\npublic:\n    vector<vector<int>> levelOrder(TreeNode* root) {\n        vector<vector<int>> answer;\n        if(!root) return a
**BFS Solution**\n```\nclass Solution {\npublic:\n    vector<vector<int>> levelOrder(TreeNode* root) {\n        vector<vector<int>> answer;\n        if(!root) return answer;  //if root is NULL then return\n        queue<TreeNode*> q;  //for storing nodes\n        q.push(root);  //push root initially to the queue\n        while(!q.empty())  //while queue is not empty go and follow few steps\n        {\n            int size=q.size();  //storing queue size for while loop\n            vector<int> v;  //for storing nodes at the same level\n            while(size--)  \n            {\n                TreeNode* temp=q.front();  //store front node of queue  and pop it from queue\n                q.pop();\n                v.push_back(temp->val);  //push it to v\n                if(temp->left) q.push(temp->left);  //if left subtree exist for temp then store it into the queue\n                if(temp->right) q.push(temp->right);  //if right subtree exist for temp then store it into the queue\n            }\n            answer.push_back(v);  //push v into answer, as v consist of all the nodes of current level\n        }\n        return answer;  //return the answer\n    }\n};\n```\n**DFS Solution**\n```\nclass Solution {\npublic:\n    vector<vector<int>> answer;\n    void DFS_levelorder(TreeNode* root,int level) \n    {\n        if(!root) return;  //if root is NULL then return\n        if(level==answer.size())  //if level is equal to answer size then we have to push one empty element into it\n            answer.push_back(vector<int> ());  //pushing extra element to accomodate next level nodes\n        answer[level].push_back(root->val);  //pushing current node to the level index of answer\n        DFS_levelorder(root->left,level+1);  //recursive call to traverse left subtree by increasing the level order\n        DFS_levelorder(root->right,level+1);  //recursive call to traverse right subtree by increasing the level order\n    }\n    vector<vector<int>> levelOrder(TreeNode* root) {\n        DFS_levelorder(root,0);  //calling function to traverse whole tree by passing root and level order\n        return answer;  \n    }\n};\n```\n**If still not understood, feel free to comment. I will help you out**\n**Thank you:)**
['Breadth-First Search', 'Queue', 'C']