text: /**
   * Definition for a binary tree node.
   * struct TreeNode {
   *     int val;
   *     TreeNode *left;
   *     TreeNode *right;
   *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
   *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
   *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
   * };
   */
  class Solution {
  public:
  vector<vector<int>> levelOrder(TreeNode* root) {
          vector<vector<int>>ans;
          
          if(root==NULL) return ans;
          
         
          queue<TreeNode*>q;
  
          q.push(root);
          while(!q.empty()){            
              int n = q.size();
              
              vector<int>v(n,0);
              for(int i=0;i<n;i++){
                  TreeNode*temp=q.front();
                  v[i]=temp->val;
                  
                  q.pop();
                  
               
                  if(temp->left){
                      q.push(temp->left);
                  }
                  
                  //check for right node : 
                  if(temp->right){
                      q.push(temp->right);
                  }
              }
              
              ans.push_back(v);
          }
          return ans;
      }
  };