class Solution {
public:
vector<vector<int>> levelOrder(TreeNode* root) {
vector<vector<int>> v;
if(root == NULL) return v;
vector<int> vv;
queue<TreeNode *> q;
q.push(root);
q.push(NULL);
while(!q.empty()){
if(q.front() == NULL){
q.pop();
v.push_back(vv);
vv.clear();
if(!q.empty()) q.push(NULL);
}
else if(q.front() != NULL){
if(q.front() -> left != NULL) q.push(q.front() -> left);
if(q.front() -> right != NULL) q.push(q.front() -> right);
vv.push_back(q.front() -> val);
q.pop();
}
}
return v;
}
};