点击打开链接
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <cstring>
#include <string.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <limits>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std;
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
class Solution {
public:
vector<int> rightSideView(TreeNode* root) {
vector<int> res;
if(root!=NULL){
queue<TreeNode*> Q;
Q.push(root);
while (!Q.empty()) {
res.push_back(Q.front()->val);
int size = Q.size();
for(int i=1;i<=size;i++){
TreeNode *node = Q.front();
Q.pop(); //所以同一级别这里删除。
if(node->right!=NULL){ //必须先放右节点
Q.push(node->right);
}
if(node->left!=NULL){
Q.push(node->left);
}
}
}
}
return res;
}
};
int main()
{
return 0;
}