Ninja technique🥷 to ACE DSA Interviews.
class Solution {
public:
vector<vector<int>> levelOrder(TreeNode* root) {
vector<vector<int>> levelorder;
if(root==NULL)return levelorder;
queue<TreeNode *> q;
q.push(root);
while(!q.empty()){
int sz=q.size();
vector<int> level;
for(int i=0;i<sz;i++){
TreeNode *node= q.front(); q.pop();
if(node->left!=NULL)q.push(node->left);
if(node->right!=NULL)q.push(node->right);
level.push_back(node->val);
}
levelorder.push_back(level);
}
return levelorder;
}
};