题目链接:https://www.nowcoder.com/practice/91b69814117f4e8097390d107d2efbe0?tpId=196&rp=1&ru=%2Fexam%2Foj&qru=%2Fexam%2Foj&sourceUrl=%2Fexam%2Foj%3Fpage%3D2%26tab%3D%25E7%25AE%2597%25E6%25B3%2595%25E7%25AF%2587%26topicId%3D196&difficulty=&judgeStatus=&tags=&title=14&gioEnter=menu
题目如下:
class Solution {
public:
vector > Print(TreeNode* pRoot) {
vector> res;
if(pRoot==nullptr) return res;
bool flag=true;//之字形标记位
queue que;
que.push(pRoot);
while(que.size()!=0){
int size=que.size();
vector path;
while(size--){
auto temp=que.front();
path.push_back(temp->val);
que.pop();//队列用完一个元素,要pop()下
if(temp->left) que.push(temp->left);
if(temp->right) que.push(temp->right);
}
//之字形反转
if(flag==false){
reverse(path.begin(),path.end());
flag=true;
}else flag=false;
res.push_back(path);
}
return res;
}
};



