vector<vector<int>> levelOrder(Node *root) {
// Your code here
vector<vector<int>> ans;
if(root == NULL) return ans;
queue<Node*> q;
q.push(root);
while(!q.empty()) {
vector<int> res;
int len = q.size();
for(int i=0; i<len; i++) {
Node *cur = q.front();
q.pop();
res.push_back(cur->data);
if(cur->left) q.push(cur->left);
if(cur->right) q.push(cur->right);
}
ans.push_back(res);
}
return ans;
}
GFG PTOD | 03 Feb | Height of Binary Tree | Medium level | Tree
Using Iteration Using Recursion