vector<int> largestValues(TreeNode* root) {
vector<int> ans;
queue<TreeNode*>q;
if(root==NULL)
{
//ans.push_back(INT_MIN);
return ans;
}
q.push(root);
while(!q.empty())
{
int s=q.size();
int maxi=INT_MIN;
for(int i=0;i<s;i++)
{
TreeNode* top=q.front();
q.pop();
maxi=max(maxi,top->val); //findinf max at the time of popping
if(top->left!=NULL)
{
q.push(top->left);
}
if(top->right!=NULL)
{
q.push(top->right);
}
}
//if(maxi!=INT_MIN)
ans.push_back(maxi);
}
return ans;
}