Simple and sweet solution's


#1

void preorder(TreeNode* temp, vector<vector> &arr,int level)
{
if(temp == NULL)
return ;

if(arr.size() == level)
    arr.push_back(vector<int>());

arr[level].push_back(temp->val);
preorder(temp -> left,arr,level+1);
preorder(temp -> right,arr,level+1);

}
vector<vector > Solution::levelOrder(TreeNode* A)
{
vector<vector> arr;
TreeNode* temp = A;
int level = 0;
preorder(temp,arr,level);
return arr;
}